NextInSection/PrevInSection order

Hi there

Anyone knows how NextInSection pages are organized?
Using NextPage i had links mixing sections, going from one to another.
Issue mentioned in

In An issue implementing .NextInSection i see an issue kind of similar to mine (from 2016).

I needed to use .PrevInSection to traverse posts, as it traverses in date order, not in the same sort order that I have displayed the content in

My links were going on reverse order of my set weights (ok, im now using prev to go to next… weird but ok)

So i guess is how to adjust weights for NextPage.
i have weights on frontmatter and on menu in config.toml.
Does it go by section weight > page weight? Does frontmatter or config.toml take precedence?

thank you for your attention

How are you ordering your pages in your range? I think that will affect this.

i… dint use a range, just copied the example code from the docs initially. Example: {{if .NextInSection}}{{.NextInSection.Permalink}}{{end}}.

My code:

{{if .PrevInSection}}
  <a class="uk-position-small uk-position-bottom-right uk-link-toggle" href="{{.PrevInSection.Permalink}}">
    <p class="uk-text-small uk-margin-remove uk-text-uppercase">{{.PrevInSection.Title}}</p>

Right. But in your list template, how are your pages ordered?

list template is the barebones one. list.html:

{{ define "main" }}
    {{ range .Paginator.Pages }}
            <h2><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
            {{ .Content }}
    {{ end }}
    {{ template "_internal/pagination.html" . }}
{{ end }}

im inserting the next/prev on the footer of the single layout. does that help? im not really sure where you were going as this isnt being used inside a range.

Where I’m going: The values of .NextInSection and .PrevInSection depend on how your pages are ordered. Based off your list template, you’re not explicitly setting the order, so it falls back to the default page order of .ByWeight.

1 Like

oooooh i see.
so, i have

folder1/ - weight: 1
folder1/ - weight: 2
folder2/ - weight: 1
folder2/ - weight: 2

it makes sense IN SECTION, but if i use nextpage it goes cross-section?
Doing some tests here and it seems that was the issue. gonna try increase all pages weight regardless of section

What Hugo version? We carefully switched the direction of these some versions ago.

Hugo Static Site Generator v0.56.3/extended darwin/amd64 BuildDate: unknown

Interesting post. I’ve found something weird too (which has just changed between 0.56.1 and 0.56.3).

I have a section with 3 pages. Each page has a weight (10, 20, 30). Date doesn’t exist (to avoid order conflicts with published date).
Now, the template has:

{{if .PrevInSection}}{{.PrevInSection.Permalink}}{{end}}<br>
{{if .NextInSection}}{{.NextInSection.Permalink}}{{end}}

My expectation is to see (page weight in brackets)

  • page1(30) with next to page2(20)
  • page2(20) with next to page3(10) and prev to page1(30)
  • page3(10) with prev to page2(20)

What I get is:

  • page1(30) has a prev to page2(20) and a next to page3(10)
  • page2(20) has a next to page1(30)
  • page3(10) has a prev to page2(20) and a next to page1(30)

Now, I’ve made some test, but I cannot explain:

  1. Why page2(20) doesn’t have a PrevInSection
  2. Why page3(10) and page1(30) generate a circular reference

I’ve tried to make page1(10) and page3(30), considering to reverse the order, but what I got was not different.
Am I doing anything wrong? (probably yes)