Search code examples
djangotemplatestemplatetag

Django (1.4) how to use with template tag to assign several variables


I am trying to assign several variables in the same with :

{% with 'Foo' as description 'Blah' as description_2 %}
...
{% endwith %}

Is there any way to achieve this ? (It works with two with)


Solution

  • Assigning multiple variables is possible with the new syntax:

    {% with description='Foo' description_2='Blah' %}
    ...
    {% endwith %}
    

    See https://docs.djangoproject.com/en/1.4/ref/templates/builtins/#with.