Reputation: 191
I'm looking to customise the sub_menu.html template with DjangoCMS, and have currently got the following code for the menu:
{% if children %}
<div class="unit subnav">
<h3>{% page_attribute "menu_title" %}</h3>
<ul>
{% for child in children %}
<li class="{% if child.selected %}on{% 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 }}" title="{{ child.get_menu_title }}">{{ child.get_menu_title }}</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
So basically, this detects if the page has children, and then adds the sub navigation if children of this page exist.
So far, so good.
My problem is that when I navigate to the child pages themselves - the menu disappears, so I'd like to detect if the page is a "child" below level 1. This should stop all pages having a nav (because they're all children of the homepage I presume) but should allow those below the main level of navigation to have the menu appear.
If anybody can lend a hand or point me in the right direction, that would be brilliant.
Upvotes: 1
Views: 2154
Reputation: 191
OK, it might not make sense to people, but I was able to get to the bottom of this with the following if statement within my subnav template...
{% if children or request.current_page.level > 0 %} subnav in here {% endif %}
Upvotes: 3