I have added a numeric param to my content’s front matter named “rating.” I want to be able to filter pages based on the rating–for example all pages where the rating is greater than 1.
Here is an example of my front mater:
---
title: "Hello World"
date: 2018-03-31T02:36:10-06:00
draft: false
description: ""
rating: 2
---
But I can’t figure our how to use this with the “where” function to filter an array. Here is an example of what I’ve tried:
{{ range where .Pages ".Params.rating" "gt" "1" }}
<p>{{ .Title }} {{ .Params.rating }} </p>
{{ end }}
This seems to return an empty array–no title are listed.
I’ve also tried this variation:
{{ range where .Pages (int .Params.rating) "gt" (int 1) }}
<p>{{ .Title }} {{ .Params.rating }} </p>
{{ end }}
…with no success.
A similar expression:
{{ range where .Pages (int .Params.rating) "ne" (int 1) }}
<p>{{ .Title }} {{ .Params.rating }} </p>
{{ end }}
…returns all pages, even those where the rating is 1.
Any suggestions?
I should note that my ultimate goal is to use the filtered array with a paginator, so simply suppressing display using {{ if (gt .Params.rating 1) )} the rating inside the range loop is not an option (but works FWIW).