Reputation: 13
I want to create variable inside "if" block and call this var in other place
{% for obj in events %}
{% if obj.calendar == instance %}
{% my_var = obj.title %}
<div class="col-md-2">
<div class="thumbnail" data-toggle="modal" data-target="#myModal">
<div class="event_title">{{ obj.title }}</div>
<div class="event_content">{{ obj.content }}</div>
</div>
</div>
{% endif %}
{% endfor %}
Upvotes: 0
Views: 312
Reputation: 15310
Use the with
statement available for standard Django templates. Example from this answer:
{% with name="World" greeting="Hello" %}
<html>
<div>{{ greeting }} {{name}}!</div>
</html>
{% endwith %}
Upvotes: 2