I am trying to figure out how to have my terms.html page only show content from a specific section. This taxonomy is used by multiple sections, but I only want the /categories/ page to show a specific section.
inside _default/terms.html
I have the following in my terms.html page:
{{ range where .Pages "Section" "projects" }}
{{ end }}
But it gives a blank page…
If I do
{{ range .Pages }}
{{ end }}
It does show everything from all sections. What am I doing wrong?
That’s strange. It should have as that’s what I’m using currently. However, I’m using it in layouts/_default/list.html. Maybe that creates a difference if you want to try?
Hi @mhal, Do you have your code in a repo somewhere we can have a look at? Please have a read through Requesting Help to see how to make it easier to get help here.
Given
[taxonomies]
tag = "tags"
# posts/lorem.md
title: Lorem
tags:
- foo
- bar
# posts/ipsum.md
title: Ipsum
tags:
- bar
- baz
Rendering {{ range .Pages }} from _default/terms.html and navigating to /tags/ should give you a list of foo, bar, baz. Their .Section would of course, be tags.
Rendering {{ range .Pages }} from _default/taxonomy.html and navigating to /tags/bar/ should give you a list of lorem, ipsum. Their .Section would then be /posts/.
So to explain a little better, I have multiple sections throughout the site that are using the same taxonomy. In my config.toml:
[taxonomies]
category = "categories"
I have multiple sections on the site using categories: project-news, projects, people.
On my _default/terms.html, I only want to have the categories listed from a specific section of the site, not all of them. I have tried the below, but it is a blank page.
{{ range where .Site.RegularPages "Section" "projects" }}
<ul>
{{ range .Pages }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a> {{ .Count }}
</li>
{{ end }}
</ul>
{{ end }}
I am certain that this range is the problem:
{{ range where .Site.RegularPages "Section" "projects" }}
I can make all the categories show, but they include the other sections I do not want.
How do I only show the categories from one section?
Are you trying to list the .Pages in /projects/ that have categories? Or are you trying to list the categories cat1cat2catx?
Do you have your site project in a repo somewhere? It is easier to help if we can see your site context and code, instead of me trying to replicate based on your description.
{{/* "layouts/_default/terms.html" */}}
<ul>
{{/* list all categories [cat1, cat2, catx] */}}
{{ range .Pages }}
{{/* for each category, check if .Pages with project section > 0 */}}
{{ if gt (len (where .Pages "Section" "project" )) 0}}
<li><a href="{{.Permalink}}">{{.Title}}</a> {{ .Section }}
<ul>
{{/* list all content .Pages under project */}}
{{ range where .Pages "Section" "project" }}
<li><a href="{{.Permalink}}">{{.Title}}</a> {{ .Section }}</li>
{{ end }}
</ul>
</li>
{{ end }}
{{ end }}
</ul>