Domanda

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

?

È stato utile?

Soluzione

Use default filter:

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

{{ s1|default:"" }}

Altri suggerimenti

You could use the elif tag.

{% if s1 %}{{s1}}{% elif s2 %}{{s2}}{% elif s3 %}{{s3}}{% endif %}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top