[Answer]-How to assign a value to a variable in the template?

1👍

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 %}
👤Selcuk

0👍

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%}

Leave a comment