Hi!
I need help . I am trying to find the way to insert conditional logic to a
baseof.html
for the “docs” section of my website to display sidebar menu only at some of the nested sections of the website.
My folder structure looks like this:
content
└── some-content-folder-1
├── page1.md
├── page2.md
└── _index.md
└── some-content-folder-2
├── page1.md
├── page2.md
└── _index.md
└── docs
├── docs-folder-section-1
├── page1.md
└── _index.md
├── docs-folder-section-2
├── page1.md
└── _index.md
...
After reading Content Sections | Hugo, I tried to use this one first:
{{ if and (eq .Parent.Section "docs-folder-section-1") (eq .Parent.Parent.Section "docs") }}
<div class=" min-w-[216px] ">
{{- partial "sidebar-docs.html" . -}}
</div>
{{ end }}
However, the partial didn’t render at content/docs/docs-folder-section-1
. Then I checked if Hugo treats it as a separate section by inserting this code in /docs/baseof.html
:
Current Page Section: {{ .Section }}
<br>
Parent Page Section: {{ .Parent.Section }}
<br>
And got this:
Current Page Section: docs
Parent Page Section: docs
Then I could only achieve desired condition with the workaround like this:
{{ if or (eq .FirstSection "docs") (in .File.Dir "docs-folder-section") }}
<div class=" min-w-[216px] ">
{{- partial "sidebar-docs.html" . -}}
</div>
{{ end }}
However, the latter seems like a hack, not the clean solution for a problem.
I would like to build the sidebar around that conditional logic for sections, so that it would render menu items of specific section where user is currently at.
Any kind of guidance is appreciated. Thanks!