Change theme:   

Filtering elements by attribute value

Let's say you have a list of Book elements (like here), each of which have a title, author and category fields. Now if on a page you want to show a filtered list of only the books from category Fiction, you can do this:

{% elementscontext category="Fiction" %}
<h2>Fiction books</h2>
        {% for fiction_book in elements %}
            <li><b>{{ fiction_book.title }}</b> by {{ }}</li>
        {% endfor %}
{% endelementscontext %}

This will give you only the books from category Fiction:

Fiction books

  • The Abilene Trail by Ralph Compton and Dusty Richards
  • Across the Nightingale Floor by Liam Hearn
  • The accidental by Ali Smith