distinct (field_name)

  • Method of Query
  • New in Lektor Version 2.0

Returns a set with all values for field_name of all Records in this query.

Example

If your blog posts have a field called tags:

# blog-post.ini

[field.tags]
name = Tags
type = strings

You can display all your blog posts' tags with:

{% set tags = site.query('/blog').distinct('tags') %}
{% if tags %}
  <ul>
    {% for tag in tags|sort %}
      <li>{{ tag }}</li>
    {% endfor %}
  </ul>
{% endif %}

Comments