For a personal project, I’d like a cyclical navigation (webring style) in a section.
Everything works fine with .Prev
and .Next
. But I’d like to add the 1st and last page when you’re at the end/beginning of the list.
My code, which works fine (there are no conditions because there are always pages in this section):
{{ $pages := .CurrentSection.Pages.ByLinkTitle.Reverse }}
{{ $prev := or ($pages.Prev .) (index (first 1 $pages) 0) }}
{{ $next := or ($pages.Next .) (index (last 1 $pages) 0) }}
<div class="webring">
<a href="{{ $prev.RelPermalink }}" title="{{ $prev.LinkTitle }}">Précédent</a>
<a href="{{ $next.RelPermalink }}" title="{{ $next.LinkTitle }}">Suivant</a>
</div>
My question is quite simple. Is it possible to list the 1st and last page without index
? I find my code rather inelegant.
And by the way, I saw that sorting could be by date (.ByDate
), weight (.ByWeight
), title (.ByLinkTitre
), but not by path. Right? I’m talking about the default filters.