Hi all,
Just getting started with Jinja2. I have a question. In my base/layout
template, I have a footer section like:
<ul id="footer-links">
<li><a href="{{ url_for('privacy') }}">Privacy Policy</a></li>
<li><a href="{{ url_for('terms') }}">Terms of Service</a></li>
<li><a href="{{ url_for('about') }}">About</a></li>
</ul>
When the user is on, say, the Terms of Service page, I'd like its list item
to have a "selected" class like:
<li class="selected"><a href="{{ url_for('terms') }}">Terms of
Service</a></li>
I'm thinking of doing this by passing down to the layout template a
"selected_page" value. Is my best bet to create a macro for creating the
list items like:
{% macro footer_link(name, text, selected_name) -%}
{% if name == selected_name %}
<li class="selected"><a href="{{ url_for(name) }}">text</a></li>
{% else %}
<li><a href="{{ url_for(name) }}">text</a></li>
{% endif %}
{%- endmacro %}
And use that in the footer? Or is there a more elegant solution I can use
where the conditional to generate the class attribute or not is "inline" on
the list item element?
Thanks,
Mike
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pocoo-libs/-/TQKS-2vHdL0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en.