Manage menu on template
This commit is contained in:
parent
a2df8314dc
commit
f6a3d64dd2
@ -1,3 +1,21 @@
|
||||
# Your global variables
|
||||
GV_base_url = "http://localhost:81"
|
||||
GV_title = "CostaPy"
|
||||
|
||||
GV_menu_navbar = [
|
||||
{
|
||||
"name":"Home",
|
||||
"href":"/",
|
||||
"roles":["guest"]
|
||||
},
|
||||
{
|
||||
"name":"About",
|
||||
"href":"#",
|
||||
"roles":["guest"]
|
||||
},
|
||||
{
|
||||
"name":"CostaPy Website",
|
||||
"href":"https://costapy.ditaajipratama.com",
|
||||
"roles":["guest"]
|
||||
}
|
||||
]
|
||||
|
@ -20,11 +20,17 @@ class main:
|
||||
|
||||
name = "World"
|
||||
|
||||
user_roles = ["guest"]
|
||||
active_page = "Home"
|
||||
|
||||
return Template(interface_template).render(
|
||||
GV_title = globalvar.GV_title,
|
||||
GV_base_url = globalvar.GV_base_url,
|
||||
topnav = Template(topnav).render(
|
||||
GV_title = globalvar.GV_title,
|
||||
menu = globalvar.GV_menu_navbar,
|
||||
user_roles = user_roles,
|
||||
active_page = active_page
|
||||
),
|
||||
footer = Template(footer).render(
|
||||
copyright_holder = "Dita Aji Pratama",
|
||||
|
@ -1,13 +1,17 @@
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
|
||||
<a class="navbar-brand" href="/">${GV_title}</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav ml-auto">
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="/">Home</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<a class="navbar-brand" href="/">${GV_title}</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav ml-auto">
|
||||
% for item in menu:
|
||||
% if any(role in item['roles'] for role in user_roles):
|
||||
<li class="nav-item ${'active' if item['name'] == active_page else ''}">
|
||||
<a class="nav-link" href="${item['href']}">${item['name']}</a>
|
||||
</li>
|
||||
% endif
|
||||
% endfor
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
Loading…
Reference in New Issue
Block a user