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?


(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.


That code just works when there is 1 level of nested folders.

Is there a way of getting the top level .CurrentSection?
I’ve tried using .Section but .Section is just the name of the top level section it is not the object.