Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Finding Pages with a certain value

Started by Muut Archive 10 years ago · 3 replies · 681 views
10 years ago

I'm probably being really thick here, but I am quite new to Grav. I'm use to ProcessWire, so coming to this amazing framework is a little confusing at times lol.

I'm trying to find child pages that contain a certain field value........for example there is a field called No. Bedrooms, and I want to find all the pages with No. Bedrooms = 3

I've searched and searched the documentation and on the forums - just can't seem to figure it out. Would someone please enlighten my confused mind :)

Cheers

10 years ago

Assuming each of your children page have a fields header.bedroomnumber you could go with something like

TWIG
{% for house in page.children if house.header.bedroomnumber == 3 %}
{{ house.title }}
{% endfor %}
10 years ago

Grav's find() function relies on path, although you can use taxonomies to find a collection of pages that are related, and then filter manually.

So the best approach I think is to use taxonomy to limit the potential pages you are going to search, then just loop over the results and pull out the ones with a certain page.header.bedroomnumber.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Muut Archive, 10 years ago
1 672 1 week ago
Archive · by Deleted User, 9 years ago
0 3043 9 years ago
Archive · by Muut Archive, 9 years ago
2 1983 9 years ago
Archive · by Muut Archive, 9 years ago
2 5336 9 years ago
Archive · by Muut Archive, 9 years ago
1 4134 9 years ago