Hugo

Array of pages with resources

I would like to build an array for pages with a particular resource. I have several other arrays that I have created using where statements for page params.

I’ve not had success with where .Resources.GetMatch "=" "portrait.*"

How would I be able to create an array of pages with a particular page resource that is not set in front matter.

EDIT: To be clear, I want to find all pages that have a particular page resource and put those pages in an array.

drop “=”

Thank you for replying.

First I tried the following

{{ $portraitValid := where “.Resources.GetMatch” “portrait.*” }}

I got this error

<where ".Resources.Ge...>: error calling where: can't evaluate the array by no match argument or more than or equal to two argument

I then tried this version

{{ $portraitValid := where .Resources.GetMatch “portrait.*” }}

and I got the following error

at <.Resources.GetMatch>: wrong number of args for GetMatch: want 1 got 0

GetMatch but will return the first match.

{{ $portraitValid := .Resources.GetMatch “portrait.*” }}
{{ with $portraitValid }} your code {{ end }}

Some thoughts on how to approach this:

  • first, get all the pages you want, then save to a variable
  • declare an empty slice
  • range that pages variable, get the match for the resource you want
  • check if the resource is nil / empty string
  • if not, append that page to the slice
1 Like