setjinja2# Store result of Jinja filter

The basics of what I am trying to do is to use the 'random' filter to choose a random item from my list but then I want to use that randomly chosen item in multiple locations.

How do I set the result of a filter to a variable that I can use in multiple locations.

If I call the 'random' filter multiple times there is little chance they will be the same.

Essentially what I want to do:

```
{% set image = {{ images | random }} %}
```

obviously this doesnt work.

Solution

Use the filter without `{{`

`}}`

delimiters.

```
{% set image = images|random %}
```

Jinja stores *globals* and *filters* in two different namespaces (dictionaries), which prevents them from being used interchangeably.

- override hive property in sprint hive jdbc
- How to type hint a subset of values from a known set in python
- Java: Enumeration from Set<String>
- Efficiently compare two sets in Python
- Is there a way to further optimize this code?
- error in creation of Set from Points
- Efficient way to count number of Set! in a table
- Which is faster and why? Set or List?
- Converting a list to a set changes element order
- Is there a Python equivalent for C++ "multiset<int>"?
- Count number of ways to pair integers 1-14 under constraint
- Does Python have an ordered set?
- Java Set retain order?
- Why don't Python sets preserve insertion order?
- How to create a std::set with custom comparator in C++?
- JavaScript Set vs. Array performance
- How can I add a property set value "intern" automatically to each new repository on artifactory 7.x?
- std::set comparator - STL Sort based on multiple attributes
- C++ sort cannot sort set of strings?
- How to get first item from a java.util.Set?
- How to get all subsets of a set? (powerset)
- Complexity of converting a set to a frozenset in Python
- list of map nested in a set
- How to Create Batch code to set each line of output into separate variables
- Why is a set object stored as a frozenset and a list object as a tuple?
- NSSet of elements with coordinates to array of columns/rows
- Do Sets exist in Go? (like in Python)
- Getting an element from a Set
- Is there an icosahedral graph in set builder notation in Haskell? (I found the other platonic graphs')
- Java LinkedHashSet backwards iteration