I have structure in hugo:
content
├── 1.md
├── a
│ ├── 2.md
│ └── 3.md
└── b
└── 4.md
and I want menu list like:
I’m using now
<ul>
{{ range .Site.RegularPages }}
<li>
<a href="{{ .Permalink }}">{{ .Name }}</a>
</li>
{{ end }}
</ul>
which gives me just:
I added
---
title: Aaaa
---
to _index.md
in a
section
structure
content
├── a
│ ├── 2.md
│ ├── 3.md
│ └── _index.md
├── b
│ ├── c
│ │ ├── 5.md
│ │ ├── 6.md
│ │ └── _index.md
│ ├── 4.md
│ └── _index.md
├── 1.md
└── _index.md
layouts/partials/walk.html
<ul>
{{ range .Pages.ByTitle }}
<li>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
</li>
{{ if .Pages }}
{{ partial "walk.html" . }}
{{ end }}
{{ end }}
</ul>
layouts/index.html (assumes you have a layouts/_default/baseof.html)
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ .Content }}
{{ partial "walk.html" . }}
{{ end }}
Note that this excludes the home page.
Thank you! Awesome code. also I want to ask, is there way to list sections first and disable creation of list pages?
I don’t understand your question. Please provide an example of what you wish to achieve.
Sorry for my english. (in menu) I want first render sections which has subpages and then standalone pages (sort in another way than .ByTitle). Also I want to prevent rendering list pages (_index.md) at all. Thanks for help again.
Sorry, but I still don’t understand what the final result should look like.
The code above produces this:
What do you want? Show me.
ddct
March 13, 2021, 11:26am
8
I haven’t tested this yet but the idea is step-by-step exactly like what you want:
<ul>
{{ range .Pages.ByTitle }}
{{ if .Pages }}
<li>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
</li>
{{ partial "walk.html" . }}
{{ end }}
{{ end }}
{{ range .Pages.ByTitle }}
{{ if not .Pages }}
<li>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
</li>
{{ end }}
{{ end }}
</ul>
onedrawingperday’s answer is for this:
This is exactly what I was looking for. Thank you all.
system
Closed
March 15, 2021, 1:15pm
10
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.