Search code examples
pythondjangodjango-mptt

recursetree code not working


I'm trying to fix a bug that appeared on a website I'm maintaining www.kenyabuzz.com the top navigation won't get the children elements. This is the code for the top nav I think {{ children }} is missing.

      {% recursetree top_menu %}
      <li{% if node.slug == '' %} id="nav-home"{% endif %} class="stackAuto">
        <a href="{% if node.url_override %}{{ node.url_override }}{% else %}{{ node.get_absolute_url }}{% endif %}" title="{{ node.title }}" class="stackContent{% if node.id == page.id or node.id == page.parent.id %} current{% endif %}">
          {% if node.slug == '' %}<img src="{{ STATIC_URL }}kb/img/kenya-buzz-logo.gif" alt="Home" />{% else %}{{ node.name }}{% endif %}
        </a>
      </li>
      {% endrecursetree %}

Solution

  • Definitely {{ children }} is missing. Your code could be for example:

    {% recursetree top_menu %}
    <li{% if node.slug == '' %} id="nav-home"{% endif %} class="stackAuto">
        <a href="{% if node.url_override %}{{ node.url_override }}{% else %}{{ node.get_absolute_url }}{% endif %}" title="{{ node.title }}" class="stackContent{% if node.id == page.id or node.id == page.parent.id %} current{% endif %}">
        {% if node.slug == '' %}<img src="{{ STATIC_URL }}kb/img/kenya-buzz-logo.gif" alt="Home" />{% else %}{{ node.name }}{% endif %}
        </a>
        {% if not node.is_leaf_node %}
            <ul class="menu children">
                {{ children }}
            </ul>
        {% endif %}
    </li>
    {% endrecursetree %}