Listing of file names for my documentation sidebar

I am addding a docs to my site.

Inside Contents folder below is the structure

└── about
|   └── _index.md  // <- https://example.com/about/
├── posts
|   ├── firstpost.md   // <- https://example.com/posts/firstpost/
|   ├── happy
|   |   └── ness.md  // <- https://example.com/posts/happy/ness/
|   └── secondpost.md  // <- https://example.com/posts/secondpost/
└── docs
    ├── doc1-folder  
          └── d1_a.md      //// <- https://example.com/docs/doc1-folder/d1_a
          └── d1_b.md
          └── d1_c.md
 
    └── doc2-folder   
          └── d2_a.md      //// <- https://example.com/docs/doc2-folder/d2_a
          └── d2_b.md
          └── d2_c.md

Now to have my sidebar for listing all docs files , I have written a partial something like this

<ul class="sidebar">
	<h3 class="header">DOC</h3>
	  {{range .Site.Home.Sections"}}
			{{ template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks}}
	 {{end}}
</ul>

But this lists all the files inside Contents folder like -About , -Posts (the posts lists) , Docs and so on.
I want it to list like this. (Expection below)

<h3 class="header">DOC</h3>
 doc1-folder (will make this accordion , just saying )
   d1_a
   d1_b
   d1_c
 doc2-folder 
   d2_a
   d2_b
   d2_c

It should list like above for sidebar , even when I am on https://example.com/docs/ OR https://example.com/docs/doc1-folder/d1_a or /doc2-folder/d2_a page.
Please help.
Basically I want to know how to list a targeted folder for documentaion sidebar

I made a working example which you can see in this repository. However, I had to add a couple of _index.md around to force .Sections to list them : /

In summary, here’s the relevant part:

<ul class="sidebar">
<h3 class="header">DOC</h3>
{{$docpage := .Site.GetPage "docs"}}
{{range $docpage.Sections}}
<li> {{ .Title }}
    <ul>
        {{range .Pages}}
        <li> <a href="{{.Permalink}}">{{.Title }}</a></li>
        {{end}}
    </ul>
</li>
{{end}}

I hope it helps!

Edit: I didn’t understand this line from your question, so I didn’t include it:

{{template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks}}
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.