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.

1
  • 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: stackoverflow.com/a/4524851/202168 Commented Dec 20, 2015 at 5:01

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.