Stone
Stone

Reputation: 749

How to known the level of current page in Django-CMS

my page.html has this

{% extends "base.html" %}
{% load cms_tags menu_tags %}

{% block title %}{% page_attribute "page_title" %}{% endblock title %}

{% block content %}
  {% placeholder "content" %}
  {% show_menu 2 0 0 100 %}
{% endblock content %}

But depend of the level of the current page I have to show different element on the page, something like this

{% if node.menu_level == 2 %}
  {% show_menu 2 0 0 100 %}
{% else %}
  #do something different
{% endif %}

How to do that? How to know the level of the current page?

Upvotes: 0

Views: 1266

Answers (1)

markwalker_
markwalker_

Reputation: 12849

I do something like this to select a relevant page title based on the ancestry of the page;

{% if request.current_page.get_ancestors|length <= 1 %}
    <h1 class="pipe-title pipe-title--inset">
        {{ request.current_page.get_page_title }}
    </h1>
{% else %}
    {% for ance in request.current_page.get_ancestors %}
        {% if ance.depth == 2 %}
            <h1 class="pipe-title pipe-title--inset">{{ ance.get_page_title }}</h1>
        {% endif %}
    {% endfor %}
{% endif %}

So you could do whatever you wanted based on the page depth in the menu tree.

Upvotes: 2

Related Questions