How to use where function?

Hi,

I have some troubles with the where function. I’m listing a list of seismic event based on a param :

content/events/2343/index.en.md

{
  "automatic": false,
  "eventType": "earthquake",
  "id": 2343,
  "latitude": -39.42,
  "longitude": 173.3,
  "magnitude": 5.6,
  "magnitudeType": "mb",
  "publishDate": "2013-02-16T05:15:33.659999Z",
  "timezone": "Pacific/Auckland",
  "url": "/en/events/2343",
  "zones": [
    "monde"
  ]
}

eventType can be equal to “quarryblast”, “earthquake” and so on.

I try in my template to filter on this parameters with the following code :

{{ $limit := 40 }}
{{ $last_events := first $limit .Data.Pages }}
{{ $earthquakes := where $last_events "Params.eventType" "eq" "earthquake" }}

I’ll get an empty array while if I range over $last_events :

{{ range $last_events }}
<p>{{ .Params.eventType }}</p> 
{{ end }}

I get a list :slight_smile:

quarry blast
induced
explosion
earthquake
earthquake
earthquake
earthquake
quarry blast
quarry blast
quarry blast
earthquake
earthquake
quarry blast

What I’m doing wrong ? I also tried with “.Params.eventType” :

{{ $earthquakes := where $last_events ".Params.eventType" "eq" "earthquake" }}

But that changed nothing ;/

Thank you for your help in advance ! I’m starting to loose my mind :slight_smile:

You need to access eventType with a lowercase accessor .Params.eventtype

Page-level .Params are only accessible in lowercase.

It’s sort of silly, so no wonder you were starting to lose your mind a little bit. :smile:

1 Like

Thank you, it works !

It’s quite disturbing as you can use the camel case name in the template and it works.

I think, I’ll only simply use lower case names for now, that’ll be easier :slight_smile:

1 Like

It’s quite disturbing as you can use the camel case name in the template and it works.

Indeed. This might be a bug. I would expect this to fail when simply doing {{ .Params.eventType }} or using .Params.eventType inside of where, based on the note in the docs.