Sergey
Sergey

Reputation: 167

how to assign a value to a variable in the template?

I have the following code:

<img src = "{{MEDIA_URL}} {{get_item_news.image}}" alt = "" style = "float: 
{% If get_item_news.inner_image_position == 'left'%} 
left 
{% Elif get_item_news.inner_image_position == 'right'%} 
right 
{% Endif%} 
"/> 

help please move if-endif block of attribute and put them before img

Upvotes: 0

Views: 45

Answers (2)

Nishant Nawarkhede
Nishant Nawarkhede

Reputation: 8400

Try this ,

{% if get_item_news.inner_image_position == 'left'%}
       <img src = "{{MEDIA_URL}} {{get_item_news.image}}" alt = "" style = "float:left"/> 
{%else%}
       <img src = "{{MEDIA_URL}} {{get_item_news.image}}" alt = "" style = "float:right"/> 
{%endif%}

Upvotes: 0

Selcuk
Selcuk

Reputation: 59174

This should work:

{% with get_item_news.inner_image_position as alignment %}
  <img src = "{{MEDIA_URL}} {{get_item_news.image}}"
       alt = "" style = "float: {{ alignment }};"/>
{% endwith %}

Upvotes: 1

Related Questions