I am currently checking a variable in the template for each menu item to find out if I should add a CSS class to highlight it.
{% if title == "Home" %}
<li class="active">
{% else %}
<li>
{% endif %}
I want to create a list containing four menu items. To get the desired effect, I will have to repeat the above code four times.
"menu":[
{"title":"home", "link":"/"},
{"title":"about", "link":"about"},
{"title":"contact","link":"contact"}
]
Is there an easier way to iterate over a list and select the corresponding item?
source
share