Hugo

Auto Generate sidebar from the folder heirarchy

I am currently using Hugo to create a developer documentation, and I have a theme which has a huge sidebar.

Since I am new to Hugo (4 days old), I don’t know if sidebars are a native feature of hugo.
If they are, is there a way to have the sidebar created directly by going through the content files?

Thanks!

(and sorry if this sounds like a stupid question :slight_smile: )

You can build sidebars from Hugo’s “content tree”. There are examples out there, variants of this recursive template:


Render the tree from the current node:

{{ template "render-section" .CurrentSection }}

Render the tree from top:

{{ template "render-section" site.Home }}

{{ define "render-section" }}
{{ range .Pages }}
Link: {{ .RelPermalink }} {{ .Title }} 
{{ if .IsSection }}
{{ template "render-section" . }}
{{ end }}
{{ end }}


{{ end }}

The above is typed now and is missing the proper HTML etc., but should show you the structure.

3 Likes