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

Find page by frontmatter item

Started by Muut Archive 11 years ago · 1 replies · 408 views
11 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 2565 9 years ago
Archive · by Muut Archive, 9 years ago
2 1689 9 years ago
Archive · by Muut Archive, 9 years ago
2 4982 9 years ago
Archive · by Muut Archive, 9 years ago
1 3806 9 years ago
Archive · by Muut Archive, 9 years ago
3 1799 9 years ago