0

Can you give me an example how can i use Navigation Nodes?

Cannot find examples in documentation.

There is this {{ node }} but where is it coming from?

Particalarly i am intereisted in {{ node.is_leaf_node }}.

Vladimir Nani
  • 2,774
  • 6
  • 31
  • 52

1 Answers1

3

Each navigation node is simply a link/entry in your menu tree so they are generated from your page layout, for example:

- Home
  - About
  - Projects
    - Project A
    - Project B
  - Contact

creates a menu with each page representing a node in the menu tree.

There's an example of them working in the default menu.html template (where child is a node in the menu):

{% load menu_tags %}
{% for child in children %}
<li class="{% if child.selected %}selected{% endif %}{% if child.ancestor %}ancestor{% endif %}{% if child.sibling %}sibling{% endif %}{% if child.descendant %}descendant{% endif %}">
    <a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>
    {% if child.children %}
    <ul>
        {% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
    </ul>
    {% endif %}
</li>
{% endfor %}
Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • I also found that but I am interested in `{{ node.is_leaf_node }}` – Vladimir Nani Apr 01 '13 at 06:38
  • It's [a term from MPTT](http://django-mptt.github.com/django-mptt/mptt.models.html#mptt.models.MPTTModel.is_leaf_node). It simply means that the node/menu-link has no children (like About & Contact above in the example) – Timmy O'Mahony Apr 01 '13 at 09:26
  • If I am in Contact, how can i know if `{{ this_node.is_leaf_node }}`? – Vladimir Nani Apr 01 '13 at 09:35
  • because it won't have any links to any other node. The menu is implemented via MPTT which is a tree-like data structure where every node has a relationship with it's parents & children so it knows where it is in relation to the other nodes – Timmy O'Mahony Apr 01 '13 at 09:41
  • The thing I am trying to achive is to show_submenu if page has children and to show sibblings if it has no children. And boy I am stuck here!! – Vladimir Nani Apr 01 '13 at 11:43
  • I solved that by creating custom tag and traversing children by my own. – Vladimir Nani Apr 02 '13 at 12:09