lektor-website/content/docs/api/db/query/distinct/contents.lr

40 lines
618 B
Plaintext
Raw Normal View History

2016-01-10 21:35:37 +01:00
title: distinct
---
summary: Returns the set of unique values for a field.
---
type: method
---
signature: field_name
---
2016-01-25 20:51:50 +01:00
version_added: 2.0
---
2016-01-10 21:35:37 +01:00
body:
Returns a `set` with all values for `field_name` of all
[Records :ref](../../record/) in this query.
## Example
If your blog posts have a field called `tags`:
```ini
# blog-post.ini
[field.tags]
name = Tags
type = strings
```
You can display all your blog posts' tags with:
```html+jinja
{% set tags = site.query('/blog').distinct('tags') %}
{% if tags %}
<ul>
{% for tag in tags|sort %}
<li>{{ tag }}</li>
{% endfor %}
</ul>
{% endif %}
```