Manage menu on template

This commit is contained in:
Dita Aji Pratama 2023-10-24 20:37:32 +07:00
parent a2df8314dc
commit f6a3d64dd2
3 changed files with 39 additions and 11 deletions

View File

@ -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"]
}
]

View File

@ -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",

View File

@ -5,9 +5,13 @@
</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 class="nav-item ${'active' if item['name'] == active_page else ''}">
<a class="nav-link" href="${item['href']}">${item['name']}</a>
</li> </li>
% endif
% endfor
</ul> </ul>
</div> </div>
</nav> </nav>