Adren echo
Adren echo

Reputation: 13

How to create and put variable into block in Django templating engine?

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

Answers (1)

Joseph Victor Zammit
Joseph Victor Zammit

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

Related Questions