Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Finding Pages with a certain value

Started by Muut Archive 10 years ago · 3 replies · 595 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 Deleted User, 9 years ago
0 2569 9 years ago
Archive · by Muut Archive, 9 years ago
2 1691 9 years ago
Archive · by Muut Archive, 9 years ago
2 4983 9 years ago
Archive · by Muut Archive, 9 years ago
1 3809 9 years ago
Archive · by Muut Archive, 9 years ago
3 1800 9 years ago