Skip to content

Instantly share code, notes, and snippets.

@dustinfarris
Last active December 20, 2015 07:39
Show Gist options
  • Save dustinfarris/6095067 to your computer and use it in GitHub Desktop.
Save dustinfarris/6095067 to your computer and use it in GitHub Desktop.
Traverse a tree in Django CMS using familiar "Next/Previous" buttons. (not sure if this will work in 3.0 when it is released) This works up to 3 levels. For more levels, append more "next" logic to the bottom. e.g. current_page.parent.parent.parent...
{% load cms_tags %}
<ul class="pager">
{% if current_page.get_previous_sibling %}
<li><a href="{% page_url current_page.get_previous_sibling %}" role="prev">&larr; Previous</a></li>
{% else %}
<li><a href="{% page_url current_page.parent %}" role="prev">&larr; Previous</a></li>
{% endif %}
{% if current_page.children.exists %}
<li><a href="{% page_url current_page.children.all|first %}" role="next">Next &rarr;</a></li>
{% elif current_page.get_next_sibling %}
<li><a href="{% page_url current_page.get_next_sibling %}" role="next">Next &rarr;</a></li>
{% elif current_page.parent.get_next_sibling %}
<li><a href="{% page_url current_page.parent.get_next_sibling %}" role="next">Next &rarr;</a></li>
{% elif current_page.parent.parent.get_next_sibling %}
<li><a href="{% page_url current_page.parent.parent.get_next_sibling %}" role="next">Next &rarr;</a></li>
{% endif %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment