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.
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.
|
in Jinja just passes the variable into the function. Simply call the function and it should work:
{% set image = random(images) %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With