Where did my Params go?

I have a taxonomy of projects. A typical project page might look like:

---
id: "community-music-sarajevo"
title: "Community Music Sarajevo"
year: 1996
date: 1996-03-01
country: "ba"
projects: "Community Music Sarajevo"
---

Suppose I now have the following code snippet:

{{ $projectsmap := site.Taxonomies.projects }}
{{ $selected := (where $projectsmap "Page.Params.country" $country.code) }}
{{ $sorted := (sort $selected "Page.Date") }}
{{ range $sorted }}
{{ .Page.Params }}
{{ end }}

My goal is to get access to all the stuff in the frontmatter of the project file. However, that .Page.Params isn’t giving me that. What I get instead looks like:

map[draft:false iscjklanguage:false title:Community Music Sarajevo]

Clearly, at some point in the process, I’m able to access the parameters loaded from the frontmatter because I use them successfully to select pages in the where clause. But if I try to get a Page from a WeightedPage then those parameters become mysteriously unreachable.

Mysteriously to me, at least. I suspect that the root problem is that there’s some part of Hugo’s data representation that I don’t understand correctly. But I’d welcome any tips that anyone could give me on figuring out the correct way to access the information I need in this case.

What is the path to the markdown file in your example?

It’s /projects/community-music-sarajevo.md in this case.

Before I get to your original question, I just want to make sure that you understand there’s a potential for page collisions here. Your content pages will render to the /public/projects directory, but so will your term pages within the “projects” taxonomy.

This is interesting. I think I’m using taxonomies wrong, and that projects should not be a taxonomy. And I suspect I’m already getting bitten by the collision issue you mentioned.

It sounds as if I should remove the projects taxonomy altogether.

Kind of smells that way…

For future reference, you can get a look at the data structure in question with this:

<pre>{{ jsonify (dict "indent" "  ") site.Taxonomies.projects }}</pre>

The pages are grouped by term. So a generic listing by term would look like:

{{ $taxonomy := "projects" }}
{{ range $term, $weightedPages := index site.Taxonomies $taxonomy }}
  {{ $termPage := site.GetPage path.Join $taxonomy $term }}
  <h2><a href="{{ $termPage.RelPermalink }}">{{ $termPage.LinkTitle }}</a></h2>
  {{ range $weightedPages }}
    <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a><br>
  {{ end }}
{{ end }}

OK, problem resolved.

The issue is that I was using taxonomies in a way that they are not designed to be used. The overlap between the taxonomy and the page hierarchy produced two problems. One was technical: collisions meant that pages at specific paths were sometimes rendered with one template, sometimes with a different one, seemingly at random. The other was conceptual: because I was thinking of taxonomy pages as pages (because I had a parallel page hierarchy that corresponded exactly to the taxonomy hierarchy) I expected to be able to get ‘page’ information – but I was accessing objects via Taxonomy and the generated taxonomy pages, naturally, had a different set of attached information.

The solution was to eliminate the project taxonomy type, which was not appropriate.

Thank you for your help.

1 Like

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