Question

I have in template and variables s1, s2, s3

<input type="text" value="{% if s1 %}{{s1}}{% endif %}{% if s2 %}{{s2}}{% endif %}{% if s3 %}{{s3}}{% endif %}" />

is there better way of doing

{% if s1 %}{{s1}}{% endif %}{% if s2 %}{{s2}}{% endif %}{% if s3 %}{{s3}}{% endif %}

?

Était-ce utile?

La solution

Use default filter:

If value evaluates to False, uses the given default. Otherwise, uses the value.

{{ s1|default:"" }}

Autres conseils

You could use the elif tag.

{% if s1 %}{{s1}}{% elif s2 %}{{s2}}{% elif s3 %}{{s3}}{% endif %}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top