minijinja::filters

Function unique

Source
pub fn unique(values: Vec<Value>, kwargs: Kwargs) -> Result<Value, Error>
Expand description

Returns a list of unique items from the given iterable.

{{ ['foo', 'bar', 'foobar', 'foobar']|unique|list }}
  -> ['foo', 'bar', 'foobar']

The unique items are yielded in the same order as their first occurrence in the iterable passed to the filter. The filter will not detect duplicate objects or arrays, only primitives such as strings or numbers.

Optionally the attribute keyword argument can be used to make the filter operate on an attribute instead of the value itself. In this case only one city per state would be returned:

{{ list_of_cities|unique(attribute='state') }}

Like the sort filter this operates case-insensitive by default. For example, if a list has the US state codes ["CA", "NY", "ca"]``, the resulting list will have [“CA”, “NY”]. This can be disabled by passing case_sensitive=True`.