i\'m very new to Jinja and Flask
I want to set different background color in the navigation bar to indicate the current page.
Is there any built-in Jinja var
There is a trick in jinja2 document for your problem: http://jinja.pocoo.org/docs/tricks/
If your list is simple enough, just using request object, something like that:
-
{{item.text}}
Normally, I write this snippet to a macro with an explicit argument to set active
:
{% macro render_sitem(endpoint, display, cls='', icon-cls='', active='') %}
-
{{display}}
{% endmacro %}
The list will be something like:
So if you have a child page which extends or includes your list, you can set active item like:
{% set active_page = 'page.index' %}
in the top of your child page.