Reputation: 1926
We've a site built in Django-CMS and have developed a mobile version with alternative CSS to suit the smaller viewing area. As well as the usual navigation bar we want to include Next and Previous page links at the bottom of each page.
I know how to output the current page's siblings using this code:
{% show_menu current_page.level %}
What is the easiest way to output links to the next and previous page?
Upvotes: 3
Views: 1354
Reputation: 1670
You can use the methods get_next_filtered_sibling
and get_previous_filtered_sibling
- but probably only for newer versions of the django cms.
Here are two template tags that return page objects which you might want to feed into the {% page_url ... %}
template tag.
@register.assignment_tag(takes_context=True)
def get_next_page(context):
current_page = context['request'].current_page
return current_page.get_next_filtered_sibling(
publisher_is_draft=False
)
@register.assignment_tag(takes_context=True)
def get_prev_page(context):
current_page = context['request'].current_page
return current_page.get_previous_filtered_sibling(
publisher_is_draft=False
)
Upvotes: 0
Reputation: 4781
You can use {{ request.current_page.get_next_sibling }}
and {{ request.current_page.get_previous_sibling }}
in your templates to show the 'neighbor' pages (not that either or b
Upvotes: 5