Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Finding Pages with a certain value

Started by Muut Archive 9 years ago · 3 replies · 492 views
9 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

9 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 %}
9 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 Deleted User, 9 years ago
0 1333 9 years ago
Archive · by Muut Archive, 9 years ago
2 924 9 years ago
Archive · by Muut Archive, 9 years ago
2 4055 9 years ago
Archive · by Muut Archive, 9 years ago
1 2933 9 years ago
Archive · by Muut Archive, 9 years ago
3 1110 9 years ago