Oskar
May 10, 2015, 3:08pm
1
Hi, how would you show a list of links to all sections? I understand they should be available in .Site.Sections.
I have the following which seems to iterate the right array but I couldn’t find any examples of what the title and permalink variables are.
<ul>
{{ range .Site.Sections }}
<li>no idea what to put here but I'd like the title of the section with a link.</li>
{{ end }}
</ul>
bep
May 10, 2015, 4:53pm
2
.Site.Sections
is just a map[string]Pages
.
The key in the map is URL root of the section, so you can do something like:
<ul>
{{ range $section, $pages := .Site.Sections }}
<li><a href="/{{ $section }}">{{ title $section }}</a></li>
{{ end }}
</ul>
The above is far from perfect. There are other threads in here that discusses this topic.
2 Likes
Oskar
May 10, 2015, 5:35pm
3
Thank you. I did search a lot without finding what I need. But yours work, thank you.
I have a content/about.md
that appears empty using your snippet. Any ideas how to only include real sections?
bep
May 10, 2015, 6:11pm
4
Not sure what “empty” means, but you should be able to put a conditional in the loop, something like:
<ul>
{{ range $section, $pages := .Site.Sections }}
{{ if ne $section "" }}
<li><a href="/{{ $section }}">{{ title $section }}</a></li>
{{ end }}
{{ end }}
</ul>
Oskar
May 10, 2015, 7:05pm
5
By empty I meant it renders the row but $section is empty. Your fix works, just getting used to get Go syntax