Correct way to hide partials in one section

I have a section called “posts”. I want to hide a certain partial in the list page of “posts” but show it in single pages. What’s the correct code to do it? if ne .Section "posts" hides in the whole section and its pages. (They are sharing the same sidebar, for single and list pages that contains this partial).

Edit: I had to add a front matter variable to the _index.md file of the section to exclude it. But is there a better way? Anyone?

{{ if and (eq .Section "posts") .IsPage }}
  {{ partial "my-partial" }}
{{ end }}

The parital will be shown only on the single pages of posts section.

The .Section is same for list and single pages of same section, you may need to check their kinds as well.

If you want to hide the partial on posts section’s list pages only.

{{ if not (and (eq .Section "posts") .IsSection) }}
  {{ partial "my-partial" }}
{{ end }}

See Page variables | Hugo.

2 Likes

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