Templating Example

Calling a navigation menu in the templates

You will need to call the navigation menu item by editing the template for the page where you want the menu to render. For example, if you want the menu to appear on all pages, you would need to call the menu in the /templates/site-name/base.html template. Using the instructions for creating a menu from the Using the Navigation Application section, we can call the menu in the template like so:

{% get_navigation_by_name "Main Menu" as main_menu %}
<ul>
    {% for child in main_menu.get_children %}
        <li><a href="{{ child.link_url }}">{{ child.label }}</a>
            {% if not child.is_leaf_node  %}
                <ul>
                    {% recursetree child %}
                        <li><a href="{{ node.link_url }}">{{ node.label }}</a></li>
                    {% endrecursetree %}
                </ul>
            {% endif %}
        </li>
    {% endfor %}
</ul>
Click to copy

Ensure that you #1 - Load the Navigation application in your load statement in the template. #2 - You are using the "Title" of the menu to call it in the get_navigation_by_name template tag.  Once complete your navigation menu will render on the desired area as follows:

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.