1

The code below is what I do when I have content with before to display:

{% if content %}
    <p> The variable contains: {{ content }}</p>        
{% endif %}

Isn't there a shortcuts that will help so that I don't check the value of content each time?

1 Answer 1

1

If you have some surrounding html code then {% if %} tag is the only solution.

But if you want to output some content in case if variable is empty then there are two useful filters:

{{ content|default:"no content" }}
{{ content|yesno:"content is True, content is False, content is None" }}
Sign up to request clarification or add additional context in comments.

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.