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

Find page by frontmatter item

Started by Muut Archive 10 years ago · 1 replies · 307 views
10 years ago

I have a blog and I have a field in my frontmatter where I define whether a post is features or not "featured: true/false". I'm looking for a way to find the posts where featured is true and can't seem to find any examples. Any ideas?

👍 1
10 years ago

By having a frontmatter setting, you would have to loop over every post and check if header.featured == true.

Something like:

TWIG
<h1>Featured Posts:</h1>
<ul>
{% for p in page.find('/blog').children if p.header.featured == true %}
  <li><a href="{{ p.url }}">{{ p.title }}</a></li>
{% endfor %}
</ul>

This is untested but should work :) BTW this was almost exactly the same as this example in the docs.

👍 1

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2959 9 years ago
Archive · by Muut Archive, 9 years ago
3 1123 9 years ago