Hi,
I’m refactoring some code I took before from a theme, but I want to make it mine with details elements instead of silly label + input + a with href, that are semantically very iffy. “Details” and summary on the other hand carry all the semantics required. Issue is I have no idea what I’m doing with loops.
Take a look:
{{ with site.GetPage "docs" }}
{{ template "section-children" (dict "Section" . "CurrentPage" $) }}
{{ end }}
{{ define "section-children" }}
<menu class=filetree>
{{ range (where .Section.Pages "Params.bookHidden" false) }}
{{ $current := eq .CurrentPage .Page }}
{{ $draft_or_wip := or .Draft .Page.Params.wip}}
{{ $ancestor := .Page.IsAncestor .CurrentPage }}
<li>
{{ if .IsSection }}
<details class="{{ if $ancestor }}open{{ end }} />
<summary class="{{ if $current }} active{{ end }}{{if $draft_or_wip}} wip{{end}}">
{{- partial "docs/title-menu" .Page -}}
</summary>
{{ template "section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }}
</details>
{{ else }}
<a href="{{ .Page.RelPermalink }}" class="content{{if $draft_or_wip}} wip {{end}}{{ if $current }} active{{ end }}">
{{- partial "docs/title-menu" .Page -}}
</a>
{{ end}}
</li>
{{ end }}
</menu>
{{ end }}
What could go wrong with this, to cause the following message ? I don’t understand any of this, save that some set is empty, but it used to work (with input etc) so I must have broken the logic somewhere.
ERROR render of “page” failed: “/home/drm/WEBSITE/layouts/_default/baseof.html:7:3”: execute of template failed: template: _default/single.html:7:3: executing “_default/single.html” at <partial “docs/menu” .>: error calling partial: “/home/drm/WEBSITE/layouts/partials/docs/menu.html:21:3”: execute of template failed: template: partials/docs/menu.html:21:3: executing “partials/docs/menu.html” at <partial “docs/menu-filetree” .>: error calling partial: “/home/drm/WEBSITE/layouts/partials/docs/menu-filetree.html:8:20”: execute of template failed: template: partials/docs/menu-filetree.html:8:20: executing “section-children” at <.CurrentPage>: can’t evaluate field CurrentPage in type page.Page
Built in 46 ms
Error: error building site: render: failed to render pages: render of “page” failed: “/home/drm/WEBSITE/layouts/_default/baseof.html:7:3”: execute of template failed: template: _default/single.html:7:3: executing “_default/single.html” at <partial “docs/menu” .>: error calling partial: “/home/drm/WEBSITE/layouts/partials/docs/menu.html:21:3”: execute of template failed: template: partials/docs/menu.html:21:3: executing “partials/docs/menu.html” at <partial “docs/menu-filetree” .>: error calling partial: “/home/drm/WEBSITE/layouts/partials/docs/menu-filetree.html:8:20”: execute of template failed: template: partials/docs/menu-filetree.html:8:20: executing “section-children” at <.CurrentPage>: can’t evaluate field CurrentPage in type page.Page
So my content looks like this:
/home/drm/WEBSITE/content
├── docs
│ ├── _index.md
│ ├── Biology
│ │ ├── _index.md
│ │ ├── fallen.md
│ │ ├── instincto.md
│ │ └── viral_phenomenon.md
│ ├── Love
│ │ ├── _index.md
│ │ ├── meta.md
│ │ └── spirituality.md
│ └── Politics
│ ├── _index.md
│ ├── ecotech.md
│ └── politics.md
└── intro.md
With the homepage being intro, thanks to module mounts ([[module.mounts]] source = "content/intro.md" target = "content/_index.md"
).
(corrected)