Page parameters on list templates

Is there a way for content displayed on a list template (via range) to respect the parameter from the content itself, instead of the page?

For example, I have content with front matter like

---
title: Team
year: 1979
---

And content like

{{ if gt .Params.year "1980" }}
this thing
{{ else }}
other thing
{{ end }}

However it seems like the content is trying to look for the list page .Params.year and not respecting the single content’s .Param. So the content will show the “this thing” content instead of “other thing” liek it should be.

Does this make sense or should I explain in more detail?

This works as expected in a list template:

  {{ range .Pages }}
    {{ if gt .Params.year 1980 }}
      GT 1980
    {{ else }}
      LE 1980
    {{ end }}
  {{ end }}

Thank you, yes, though if the page using the list template already has a year = 1950 is there a way to circumvent that for each post presented?

I’m not following you.

Sorry, let me start over with a different approach.

I have content files that display a different piece of content, as demonstrated above, depending on the .Params.year value of the page.

For a list page, that may or may not have .Params.year associated with it, I want to show a list of those content files, but for each post it finds, it needs a different .Params.year assigned to it.

For example, I’m showing logo changes for the Detropit Pistons. The SVG file is set up to display the correct logo for each year, using the if gt .Params.year "1980" type of code block above.

What I’m running into is that despite each content having its own year: 19xx parameter in their frontmatters, I’m only getting one year of content showing.

This is not the fault of my SVG sprite, which is working correctly on other list templates. For instance, I have pages from 1984-2023 (in the content files they each have year: 1984 frontmatter, and so on) which each correctly reference my SVG file and display the correct SVG code according to the if/else statements.

File structure is:

I have layouts/teams with

list.html

{{ range .Pages }}
    <svg width="50" height="50" role="img">
            <title>{{ .Title }}</title>
        <use xlink:href="#{{ .Params.team }}">
    </svg>
    <a href="{{ .Permalink }}">{{ .Title }}</a>
{{ end }}

Which, at URL/teams/pistons/ gives me

Is there a way to have each post respect its own .Params.year in a list template?

Sorry to be dense, but, what’s wrong with what you’re showing at URL/teams/pistons/?

It’s not you being dense, it’s me trying to explain a complicated situation :sweat_smile: Sorry, and thank you for your patience.

I have an SVG sprite set up like this:

{{ if gt .Params.year "2006" }}
newest logo
{{ else if gt .Params.year "2002" }}
next oldest logo
{{ else if.. }}

and so on. In this case, the .Params.year is not being respected, it seems.

Although I don’t completely understand the problem, I just noticed that you are comparing a string to an integer.

Hmm, should I be doing something like this then?

{{ if gt (int .Params.year) "2006" }}

The previous method is working in other areas of my site?

See my initial response for the correct syntax.

And, unfortunately, I still don’t understand the problem. The screen captured that you posted with the five or six images looked right to me. I don’t understand the problem, and I don’t have enough to work with.

Ok, thank you. I’ll keep trying different things on my end, and will spin up a test repo if I still can’t figure it out.

Just make a variable for your page param and use @jmooring code

Thanks @benmarte, does this do something to the scoping to help my situation? Currently the SVGs in my partials folder are referencing .Params.year, so that’s why I’m trying to target that in content renders in the list template.

Yup, it’s creating a $data var for your .Params.year in the frontmatter so you don’t have collisions with the one in your range.