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