Tuesday, 10 September 2013

How can I determine if a Jinja2 template block is empty?

How can I determine if a Jinja2 template block is empty?

I'd like to detect if a Jinja2 template block content is empty or not.
Something like this:
{% block foo %}{% endblock foo %}{% if foo %} - {% endif %}Blah Blah Blah
What I want is conditional text outside the block definition itself. In
the contrived example, I want to be able to insert a conditional string -
after the block if and only if the block has been overridden and is not
empty.
Is this possible?

No comments:

Post a Comment