{{/* Emits PREVIOUS and NEXT buttons based on the pages in the current directory, ordered by page weight. */}} {{ $currentPage := .Page }} {{/* Get the pages in the current directory. */}} {{ $unsortedPages := slice $currentPage }} {{ if eq $currentPage.File.Dir $currentPage.Parent.File.Dir }} {{ $unsortedPages = $unsortedPages | append $currentPage.Parent }} {{ end }} {{ range $index, $page := .Page.CurrentSection.Pages }} {{ if and (gt $page.Weight 0) (ne $page.RelPermalink $currentPage.RelPermalink) }} {{ $unsortedPages = $unsortedPages | append $page }} {{ end }} {{ end }} {{/* Sort by weight. */}} {{ $pages := sort $unsortedPages "Weight" }} {{/* Set the first and last indexes. */}} {{ $first := 0 }} {{ $last := sub (len $pages) 1 }} {{/* Determine the index of the current step. */}} {{ $step := -1 }} {{ range $index, $element := $pages }} {{ if eq $element.RelPermalink $currentPage.RelPermalink }} {{ $step = $index }} {{ end }} {{ end }}