I’m trying to develop a tailor user manual and need to retrieve the previous or next item based on current item.
It seems to work, but I don’t know if it is the best way…
url = "/guide/:slug"
layout = "internal_pages"
title = "Pagina manuale"
meta_title = "{{ page.title }}"
meta_description = "{{ page.summary_text }}"
[section page]
handle = "Manuale"
entrySlug = "{{ :slug }}"
[collection manuale]
handle = "Manuale"
==
{% if page is empty %}
{% do abort(404) %}
{% endif %}
{% set next = manuale.where('nest_left', '>', page.nest_left).first() %}
{% set prev = manuale.where('nest_left', '<', page.nest_left).orderBy('nest_left', 'desc').first() %}
<div class="col-6 text-end">
{% if prev %}
<a href="{{ 'risorse/manuale/pagina-manuale'|page({ slug: prev.slug }) }}"><i class="uil uil-arrow-circle-left"></i> {{prev.title}} </a>
{% endif %}
</div>
<div class="col-6 text-end">
{% if next %}
<a href="{{ 'risorse/manuale/pagina-manuale'|page({ slug: next.slug }) }}">{{next.title}} <i class="uil uil-arrow-circle-right"></i></a>
{% endif %}
</div>