1

For simple template

{% with var1="super" var2="man" %}
    <p>
        {{ var1 }}
        {{ var2 }}
    </p>
{% endwith %}

gives super man but I want superman.

{% spaceless %} does not work for this case (between two strings, not two tags.)

What is the solution? Making {{ var1 }} and {{ var2 }} in one line is actually too long in my code.

User
  • 37
  • 4
  • 1
    you should just put the values next to each other and live with having a 'long' line in your code. alternatively you could concatenate them into a single template variable: http://stackoverflow.com/a/4524851/202168 – Anentropic Dec 20 '15 at 05:01

2 Answers2

1

The solution is simple, just remove the enter character:

{% with var1="super" var2="man" %}
    <p>
        {{ var1 }}{{ var2 }}
    </p>
{% endwith %}

But if you don't want to make the code as you said "long" ( I don't know the reason :) ), you can combine the variables two by two and merge them and so on.

Needless to say, as long as you have HTML file, it will interpret the enter character as a space in <p></p>, so your problem isn't really a django/python problem, because the problem is between the tags, not the tags themselves.

P3zhman
  • 243
  • 3
  • 12
0

Look at what the "problem" is differently.

{% with v1=var1 %}
{% with v2=var2 %}
    {{ v1 }}{{ v2 }}
{% endwith %}
{% endwith %}

Though technically less efficient here, in a lot of cases readability is more important than saving a few bits or cycles.

Kevin
  • 2,234
  • 2
  • 21
  • 26