Show only part of taxonomies

Hi All!

Is there a way to show only a part of taxonomies?

Let’s say I have files with two taxonomies in front matter:

sdlc_phases
jtbd_processes

What I want to do is show “jtbd_processes” terms related to some particular sdlc_phase only.

Example:

File 1

sdlc_phases:
- a
jtbd_processes:
- 1

File 2

sdlc_phases:
- a
jtbd_processes:
- 2

File 3

sdlc_phases:
- b
jtbd_processes:
- 3

So I want to list only processes 1 and 2 for phase a.

{{ range .Site.Taxonomies.jtbd_processes }} - shows all processes and I have no idea how to narrow it down to given sdlc_phase.

Thanks for any help!

Since you are relating two taxonomies via the content pages to which they are applied, you need to range through the relevant content pages, build a slice of the related terms, remove the duplicates, then range through the resulting slice.

{{ $s := slice }}

{{ range where site.RegularPages "Params.sdlc_phases" "intersect" (slice "a") }}
  {{ range .GetTerms "jtbd_processes" }}
    {{ $s = $s | append (dict "RelPermalink" .RelPermalink "LinkTitle" .LinkTitle) }}
  {{ end }}
{{ end }}

{{ $s = uniq $s }}

{{ range $s }}
  <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a><br>
{{ end }}
2 Likes

OMG - thank you for such complex answer - working like a charm! :slight_smile:

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