Pergunta

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

?

Foi útil?

Solução

Use default filter:

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

{{ s1|default:"" }}

Outras dicas

You could use the elif tag.

{% if s1 %}{{s1}}{% elif s2 %}{{s2}}{% elif s3 %}{{s3}}{% endif %}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top