Is there a way to display a section’s title? I have a title in the _index.md file, but can’t figure a way to display it as what is returned is the title with underscores. ie: (my_section) whereas I would like “My Section” to show up.
I am showing this on a sidebar nav, where I would always like to have the section title shown at the top regardless of the child menu items being clicked, so am unable to call just {{ .Title }}.
New to Hugo, and can’t seem to figure this out.
<h4><a href="/{{ .Section }}">{{ .Section }}</a></h4>
maiki
November 22, 2018, 7:33pm
2
Please share your project code, or a sample project that reproduces the issue you’re having. That way we can look at it and clone it and assist ya.
Oops- sorry, here is the full code
{{ $thisSection := .Section }}
{{ if (index .Site.Menus $thisSection) }}
<ul>
{{ $currentPage := . }}
<li>
<h4><a href="/{{ .Section }}">{{ .Section }}</a></h4>
</li>
{{ range (index .Site.Menus $thisSection) }}
{{ if .HasChildren }}
<li class="{{ if $currentPage.IsMenuCurrent $thisSection . }}active{{ end }}">
<a href="{{ .URL }}">
{{ .Pre }}
<span>{{ .Name }}</span>
</a>
</li>
<ul class="list-reset">
{{ range .Children }}
<li class="{{ if $currentPage.IsMenuCurrent $thisSection . }}active{{ end }}">
<a href="{{ .URL }}">{{ .Name }}</a>
</li>
{{ end }}
</ul>
{{ else }}
<li class="{{ if $currentPage.IsMenuCurrent $thisSection . }}active{{ end }}">
<a href="{{ .URL }}">
{{ .Pre }}
<span>{{ .Name }}</span>
</a>
</li>
{{ end }}
{{ end }}
</ul>
Try this. Might work as a good starter.
<ul>
{{ range where .Site.Pages "Section" .Section }}
<li>{{ .Title }}</li>
{{ end }}
</ul>
Thanks for suggestion Leo_Merkel.
I ended up using this to show the Section title with correct formatting:
{{ .Section | humanize }}
1 Like