'Complement' from a partial

Is it possible to use complement from a partial? I am making a sidebar for a list page as a partial. The sidebar should show a list of pages related to the nested section that is opened in the browser.

{{- $p := $.Pages | complement $paginator.Pages | shuffle | default 5) }} 

Assuming this content…

content/
β”œβ”€β”€ s1/
β”‚   β”œβ”€β”€ s1-1/
β”‚   β”‚   β”œβ”€β”€ _index.md
β”‚   β”‚   β”œβ”€β”€ p1.md
β”‚   β”‚   β”œβ”€β”€ p2.md
β”‚   β”‚   └── p3.md
β”‚   └── _index.md
└── _index.md

1) What should be shown in the sidebar when viewing content/s1/s1-1/_index.md ?
2) What should be shown in the sidebar when viewing content/s1/s1-1/p1.md ?

Posts from that nested section only (so, p1, p2. etal).

I use a different sidebar for single pages. So, that’s not an issue for now.

From the template that renders content/s1/s1-1/_index.md

{{ partial "pages-in-current-section.html" . }}

layouts/partials/pages-in-current-section.html

{{ with .CurrentSection.Pages }}
  <ul>
    {{ range . }}
      <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
    {{ end }}
  </ul>
{{ end }}
git clone --single-branch -b hugo-forum-topic-48495 https://github.com/jmooring/hugo-testing hugo-forum-topic-48495
cd hugo-forum-topic-48495
hugo server

Before I test this, I came upon your comment on multi-page posts some months back and implemented option 2 which is included in $paginator. Will this code work without splitting the individual pages inside multipage to show up as related in the sidebar?

Please test it and then come back to me if you need additional help.

It works. Disregard my previous comment.

And since you said you are only using this on section pages, you can just do:

{{ with .Pages }}
  <ul>
    {{ range . }}
      <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
    {{ end }}
  </ul>
{{ end }}
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.