How to render lists of the same term from different taxonomies?

On my site I have taxonomies authors and translators. For an author I want to display two lists: where he is an author and where he is a translator.

I have a partial, which uses a paginator, displaying the lists in their separate taxonomy list.html today. So I am hoping to be able to list both taxonomies with separate paginators.

Here’s the gist of my authors list.html template:

{{ define "main" }}

<h1>{{ .Title }}</h1>

<h2>Author of:</h1>

{{ .Scratch.Set "where" .Data.Pages }}

{{ partial "default.html" . }}

{{ end }}

I’m thinking that I should be able to list the post where the same term exists in translators by something inserted between the partial and the {{ end }}. there. Making the template something like:

{{ define "main" }}

<h1>{{ .Title }}</h1>

<h2>Author of:</h1>

{{ .Scratch.Set "where" .Data.Pages }}

{{ partial "default.html" . }}

{{ if something }}

   {{ with something }}

    <h2>Translator of:</h1>

    {{ .Scratch.Set "where" .Data.Pages }}
    {{ partial "default.html" . }}
   {{ end }}

{{ end }}

{{ end }}

But having tried some different something1 and something2, I am starting to doubt this approach.

Can it be done? If so, how? :smile:


you have collections site.Data.Authors and site.Data.Translators

look in my sample repo under layout/tags for how to list taxonomies

So, in the authors list, you can range over and compare the names

don’t give you a complete solution now, try to make it self :wink:

1 Like

So, I have tried to figure this out a while now. I don’t see how listing taxonomies help me. The way I understand my problem I first have to figure out the term for the displayed author page, then I want to list all translator pages using that term.

I fail at the first thing there, figuring out the term (the author) for a given author page. And then it is unclear to me how I can range of the pages for that term in a different taxonomy.

can we get an repository for help?

in the authors list - something like this

{{ where site.taxnomies.translators "Title" .Title }}

.Title is the authors name
looks in the translators collection for the same name

Thanks! Why didn’t I think about matching on something else… haha.

I’ll run with this and see where (hehe) it gets me.

So, now I have this:

{{- $author := .Name -}}

{{ .Scratch.Set "where" .Data.Pages }}

{{ partial "default.html" . }}

{{ range where .Site.Pages "Params.translators" "ne" nil }}
  {{- $translator := index (.Params.translators) 0 -}}
  {{ if (eq $translator $author) }}
    <a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
  {{ end }}
{{ end }}

Not sure if I could get rid of the if with a smarter where, but anyway, this works for giving me the pages I want.

Next step is less clear for me. My default.html partial takes care of paging the listing. I’m not quite sure how it works, but this is happening in the partial:

{{ $paginator := .Paginate (where (.Scratch.Get "where") "Section" "artiklar") }}
{{ range $paginator.Pages }}

So the Scratch.Set "where" .Data.Pages makes sense. But inside my range there I have one page at a time…

if you work with different sets, this could help

or this

It seems I cannot do what I want to do. From

The .Paginator is static and cannot change once created.

So paginating two lists of pages is not possible using the .Paginator. Oh, well, it was a fun exercise! :smile:

yes, you can do something like this

{{ $paginator := .Paginate $pages.Pages 20}} 
{{ range $paginator.Pages -}}
	{{ .Render "summary" }}
{{- end }}

Unfortunately I can’t. The list of author summaries is already paginated on the same page. So that second invokation of .Paginate doesn’t do anything. I just get the authors list again.