SolessChong
SolessChong

Reputation: 3407

Django-cms show menu: How to show menu under current page?

I'm totally confused by django-cms's show_menu tag. There are four parameters but no full document on these parameters could be found. There are only several exmaples however I cannot find how to show menu under current page only.

Pages are arranged like this:

--Projects
----proj1
----proj2
--Gallery
----gal1
----gal2

In Projects template, how do I set the parameters for show_menu to show only the menu under current page?

Update

@Brandon

I tried exactly this:

{% show_sub_menu 1 "menu/cust_menu.html" %}

As exactly what the document says. However it ends up in this error:

u'menu/cust_menu.html' could not be converted to Integer

Upvotes: 2

Views: 3911

Answers (2)

BangTheBank
BangTheBank

Reputation: 828

There is actually an error in documentation and it seems to be also a little bug introduced in one of the last versions of django cms (planned to be solved in django-cms 3.0 version!).

https://github.com/divio/django-cms/issues/1913

I solved using this:

{% show_menu_below_id "topics_page" 0 4 100 100 "./_menus/menu_topics.html" %}

where "topics_page" is the reverse id (you configure it in advanced section in cms admin).

For recursive rendering of menu, just configure the custom id of subpages for which you want display the next menu level;

in your custom menu template, you can play with child properties and the for loop counter. Below, check a nasty example but still useful if you want to customize your menu template:

{% load menu_tags %}
{% load template_extras %}

{% for child in children %}
    {#    sub voices topics   #}

    {% if child.level == 1 %}
        {% if not forloop.counter|divisibleby:2 %}
            <div class="row-fluid">
        {% endif %}
    <div class="span6">
        <div class="sub1">
            <a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}"><span
                    class="icon-play"></span>{{ child.get_menu_title|capfirst }}</a>
        </div>
        {% if child.children %}
            {% show_menu_below_id child.attr.reverse_id 0 4 100 100 template %}
        {% endif %}
    </div>
    {% if forloop.counter|divisibleby:2 %}
        </div> <!-- end row fluid -->
    {% endif %}


    {% elif child.level == 2 %}
        {#        2 - {{ child.attr.reverse_id}} - {{ child.get_menu_title }}#}
        <div class="row-fluid">
            <div class="span11 offset1">
                <div class="sub2">
                    <a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title|capfirst }}
                    </a></div>
            </div>
        </div>
        {% if child.children %}
            {% show_menu_below_id child.attr.reverse_id 0 4 100 100 template %}
        {% endif %}
    {% elif child.level == 3 %}
        {#    leaf node topics   #}
        {#        3 - {{ child.attr.reverse_id}} - {{ child.get_menu_title }}#}
        <div class="row-fluid">
            <div class="span10 offset2">
                <div class="sub3"><a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">
                    <i class="icon-list-alt"></i> &nbsp;{{ child.get_menu_title|capfirst }}</a></div>
            </div>
        </div>
    {% endif %}
{% endfor %}

Upvotes: 0

Brandon Taylor
Brandon Taylor

Reputation: 34553

You need to use:

{% show_sub_menu 1 %}

http://django-cms.readthedocs.org/en/2.1.3/advanced/templatetags.html#show-sub-menu

Upvotes: 2

Related Questions