stable
  • User Guide
  • Developer Guide
  • Cookbooks
  • Best Practices
  • Reference
    • Modules
    • Actions
    • Controllers
    • All dispatch rules
    • Filters
      • Binaries
      • Booleans
      • Dates
      • Encryption
      • Character escaping
      • Forms
      • HTML
      • Lists
      • Mailing list
      • Menu
        • menu_flat
        • menu_is_visible
        • menu_rsc
        • menu_subtree
        • menu_trail
      • Miscellaneous
      • Numbers
      • Regular Expressions
      • Resource lists
      • Resources
      • Strings
      • Survey
      • Translation
      • Tuples
      • Variables
    • Models
    • Services
    • Builtin Tags
    • Custom Tags
    • Validators
    • Directory structure
    • Icons
    • Notifications
    • Installation requirements
    • Global configuration
    • Site configuration
    • The Status site
    • Command-line
    • Transport
    • Troubleshooting
    • EDoc reference
  • Glossary
Zotonic
  • Docs »
  • Reference »
  • Filters »
  • Menu »
  • menu_trail
  • Edit on GitHub

menu_trail¶

  • Module: mod_menu

Return a breadcrumb navigation trail for the given id.

This filter locates the filter value which represents the current page in the main menu or in the menu saved in the resource of the given id.

For example:

{% print id|menu_trail:55 %}

Could print the list [13, 33] if ids 13 and 33 are the parents of the id argument in the menu resource 55.

If no argument is given, it takes menu from the resource with the name main_menu.

Showing Menu Trail only for submenu items¶

It is sometimes useful to suppress the menu trail on top level items. Here is how to do it.

The menu_trail includes the whole path through the menu to the current page if it is reachable that way. Sometimes it may seem pointless to show the menu trail if we are on the first level of the menu. If we want to avoid this we need to avoid rendering a trail when it is less than two items long.

One simple condition change to _article_chapeau.tpl from the blog skeleton makes this work:

{% with id|menu_trail as parents %}
  {% if parents|length > 1 %}
  <h5 class="chapeau">
  {% for p in parents %}
  <a href="{{ m.rsc[p].page_url }}">{{ m.rsc[p].title }}</a>
  {% if not forloop.last %}&raquo;{% endif %}
{% endfor %}</h5>{% endif %}{% endwith %}

The key here is {% if parents|length > 1 %} in place of just {% if parents %}.

The if tag is now rendering the menu_trail only if there are two or more items in it which - as I mentioned before - happens when you are at least two levels deep in the menu.

See also

menu_subtree, menu_flat

Next Previous

© Copyright 2009–2017, The Zotonic Project (zotonic.com). Revision f600c2bd.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: stable
Versions
latest
stable
0.x
Downloads
pdf
htmlzip
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.