Michael JDI
Michael JDI

Reputation: 1251

Hugo - Access .Pages from the context of the list template from within the context of the single template

The documentation for hugo says the the .Pages variable inside the context of the single page is blank and that the .Pages variable from the context of the list page is populated.

I want to access the .Pages variable from the list page INSIDE the context of the single page.

How do I do this?

Documentation is below: enter image description here

Upvotes: 0

Views: 307

Answers (1)

Michael JDI
Michael JDI

Reputation: 1251

Worked through the issue here is what I came up with. This snippet:

 {{ $currentPage := . }} 
{{ range .Site.Pages }}
    {{ if .InSection $currentPage}} 
        {{ if .IsAncestor $currentPage }} 
            {{ else }}
                <li>
                    <a class="nav-link active" href="{{.Permalink}}">{{.Title}}</a>
                </li>
        {{ end }} 
    {{ end }} 
{{ end }}

Upvotes: 1

Related Questions