Section List when viewing a section (solved)

I’m trying to list all posts in a section on a page within that section (not the list). Is this possible?

It seems from the docs that .Paginator is only available from lists and the homepage. When I try ranging over .Section.Pages, nothing comes out.

Am I missing something? Is this possible?

Thanks!

Here’s how I’ve done it:

1 Like

Thanks, Matt. What I was trying to do though was not just show the adjacent posts in a series but all posts in the series.

Thankfully I found a design workaround so it’s no longer necessary, but I’m still curious if it is possible.

@SamPotasz Here is one way to do it. :wink:

    {{ range where .Site.Pages "Section" "service" }}
      {{ if isset .Params "templatename" }}
        {{ .Render .Params.templatename }}
      {{ else }}
        {{ .Render "service-default" }}
      {{ end }}
    {{ end }}

This is in my section folder under the layouts folder with the name service.html.

Oh nice. I think then you can probably use the techniques discussed over here to generalize to all sections. As in, you could programmatically find the name of any section and not have to specify “service” or create a “service.html” file

Also, it may be accomplishable with menus?

In my case, I want to be able to specify the sections. I am sure you are correct.

The great thing here is that Hugo allows for some pretty good solutions. Easy and fast to solve.

Menus in that example are using Params in the config and would require you to update your config file as you add them.

If you want to create a menu using taxonomies, you could use something like:

<section>
  <ul>
    {{ range $taxonomyname, $taxonomy := .Site.Taxonomies }}
      <li><a href="{{ "/" | relLangURL}}{{ $taxonomyname | urlize }}">{{ $taxonomyname }}</a>
        <ul>
          {{ range $key, $value := $taxonomy }}
          <li> {{ $key }} </li>
                <ul>
                {{ range $value.Pages }}
                    <li hugo-nav="{{ .RelPermalink}}"><a href="{{ .Permalink}}"> {{ .LinkTitle }} </a> </li>
                {{ end }}
                </ul>
          {{ end }}
        </ul>
      </li>
    {{ end }}
  </ul>
</section>

Getting off subject here.

OK, super simple solution.

{{ range where .Site.Pages "Section" .Section }} <a href="{{ .Permalink }}"> <h2 class="post-title">{{ .Title }}</h2> </a> {{ end }}

1 Like

Very Good. Now I understand where you were going with your question. You meant to list the section you are on. Very elegant and easy.

Could rename this thread to “Section List when viewing a section”

1 Like