I'm trying to unpack more than one variable on jinja template engine. How can I achieve this?
I'm trying to achieve something like this;
{% for item1, item2, item3 in items %}
<div class="row">
<div class="four columns">
<img src="static{{ item1.pics.0 }}" class="picitem" alt=""/>
</div>
<div class="four columns">
<img src="static{{ item2.pics.0 }}" class="picitem" alt="" />
</div>
<div class="four columns">
<img src="static{{ item3.pics.0 }}" class="picitem" alt=""/>
</div>
</div>
{% endfor %}
This is obviously not working by giving;
ValueError: too many values to unpack
Any ideas would be appreciated.
there are two delimiters to split by here: first it's ",", and then the elements themselves are split by ":".
Variables. Template variables are defined by the context dictionary passed to the template. You can mess around with the variables in templates provided they are passed in by the application. Variables may have attributes or elements on them you can access too.
Use the batch
filter to iterate over chunks:
{% for tmp in items|batch(3) %}
<div class="row">
{% for item in tmp %}
<div class="four columns">
<img src="static{{ item.pics.0 }}" class="picitem" alt=""/>
</div>
{% endfor %}
</div>
{% endfor %}
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