I have a shortcode that I want to pass in a parameter and then only show items in a data file if they have the matching parameter in one of the data items.
I have a data file that has items like:
- title: cool item
url: someurl
featured: core
In the shortcode I want to pass in core
and then only show those items that have featured = core.
I have tried this:
{{ range .Site.Data.products.items }}
{{ if eq .featured (.Get 0) }}
//do cool stuff here
{{ end }}{{ end }}
But I get an error about Get is not a method but has arguments.
If I just hard code the if part as {{ if eq .featured "core" }}
it works great. Likewise if I put {{.Get 0}}
outside the if I can get core
.
How can I get the comparison to use the parameter? It seems like I need to assign .Get 0 to a variable and then use that in the if statement but I don’t see anything in the docs about that - though I did read about Scratch and that sounded close but I didn’t see an example that made any sense to me.