سؤال

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

?

هل كانت مفيدة؟

المحلول

Use default filter:

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

{{ s1|default:"" }}

نصائح أخرى

You could use the elif tag.

{% if s1 %}{{s1}}{% elif s2 %}{{s2}}{% elif s3 %}{{s3}}{% endif %}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top