I would like to write a partial for all pages inside guides/ which creates “next” and “previous” links. The key functionality is for:
the next/prev links to work across multiple folders i.e. the last page in chapter-one/ links to the first in chapter-two/.
the next/prev links to appear on both _index.md pages and normal pages.
I am aware of how to weight pages, but not how to get something working across multiple folders.
My current attempt is not working. I have currently created a very basic partial which uses {{ $pages := .CurrentSection.Pages.ByWeight.Reverse }} with {{ with $pages.Prev . }} and {{ with $pages.Next . }} and I call this partial in both the section.html and single.html layout files. I can create next/prev links in the singles pages only, but nothing is showing in the section pages (i.e. the _index.md files), and I’m not sure where to start for achieving linking across folders (i.e. the first bullet point described above.)
I can see that the pager buttons traverse the chapters according to their weighting. But I also see that the _index.md files are not included? In your repo, category-one/_index.md does not contain the pager buttons, nor is it linked to as the ‘previous page’ in category-one/page-one.md.
In my website, the _index.md files will need to be included because they serve as landing pages for each chapter (like somebody reading a book).
Maybe you know what small modification needs to be made?
I think you’ll need to walk the content to build the page collection.
Given that you need this collection on every page, I would build it once and stuff it in a site Store. Building the collection every time you render a single page will get expensive (i.e., why do something 1000 times when you can do it once?) build the page collection in a partial then call it with partialCached.
I’m not sure if that’s addressed to me or @Travis_Beckham but unfortunately I am not a very advanced Hugo user. I would need more information on how to walk through all my files and assign an ordered list of all the pages to a single variable.
As I mentioned earlier, I initially tried with {{ $pages := .CurrentSection.Pages.ByWeight.Reverse }} but this only worked inside a single folder and did not include the _index.md files.
git clone --single-branch -b hugo-forum-topic-54465 https://github.com/jmooring/hugo-testing hugo-forum-topic-54465
cd hugo-forum-topic-54465
hugo server