Exclude pages by "type" from 'NextInSection'

If you want the next page in the section which does not have a certain value for a parameter, you may need to use a recursive partial. This is because .NextInSection is not a collection that you can filter, but just a single page.

Here’s an example of how you could create a recursive partial

// in the base template

{{ partial "nextpage" . }}
// in /layouts/partials/nextpage.html

{{ with .NextInSection }}
  // Check if the next page is a teaser
  {{ if eq .Params.Type "teaser" }}
    // if so, try the next next page (this creates recursion)
    {{ partial "nextpage" . }}
  {{ else }}
    // otherwise render the next page link
    <a href="{{ .RelPermalink }}"> Next Page </a>
  {{ end }}
{{ end }}