Get the last section

Hi everyone,

I just discovered sections on Gohugo, I’m building a website where each section (and subsequentially each folder under content/courses folder) is a course that I’d like to create for my readers.

One of the features I want to give to my readers is the fact to have a lateral menu where they could explore the pages per each course. I have some difficulties at building one page for all the courses that have the navbar.

In particular, I have some difficulties at taking pages on the same sub-section (aka on the same course).
This is the code I’m using.

   {{ $pages := where .Site.Pages ".Section" .Section}}
             {{ range ($pages.ByParam "position") }}
                        <li class="nav-list-item"><a href="{{.Permalink}}" class="nav-list-link">{{.Title}}</a></li>

At the moment all pages served under /courses folder are being taken. But I would like only /courses/$name_of_course where $name_of_course is the last category.

1 Like

Hi there,

Do you have your site code in a repo somewhere we can have a look at? It is easier to help if we can replicate your issue. Please have a read about Requesting Help