Created
September 22, 2013 10:27
-
-
Save alexandresalome/6658708 to your computer and use it in GitHub Desktop.
Reduce amount of logic in your templating: set business in your array definition, not in template body.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="nav navbar-nav"> | |
{% set navbar_active = navbar_active|default(null) %} | |
{% set navbar_menu = navbar_menu|default([ | |
{ | |
'show': app.user and is_granted('ROLE_ADMIN'), | |
'active': navbar_active == 'design', | |
'label': 'Design', | |
'href': path('admin_design'), | |
}, | |
{ | |
'show': app.user and is_granted('ROLE_ADMIN'), | |
'active': navbar_active == 'administration', | |
'label': 'Administration', | |
'href': path('adminuser_list') | |
}, | |
]) %} | |
{% for menu in navbar_menu %} | |
{% if menu.show|default(true) %} | |
<li{% if menu.active|default(false) %} class="active"{% endif %}> | |
<a href="{{ menu.href }}">{{ menu.label }}</a> | |
</li> | |
{% endif %} | |
{% endfor %} | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
menu.show|default(true)
will not do what you expect, because afalse
value will give you the default, so the item will always be shown