Search code examples
pythontemplatesjinja2

Applying jinja2 filters to a block?


Is it possible to apply jinja2 filters to {% block ... %} constructs? What I was hoping to do was something along the lines of:

{% block content|upper %}
here is some content that will be rendered in upper case
{% endblock %}

...but this doesn't work; the above example will result in an error. Is there any other way to wrap a chunk of template text in a jinja2 filter?


Solution

  • You can use filter sections:

    {% block content %}
        {% filter upper %}
            Here is some content that will be rendered in upper case.
        {% endfilter %}
    {% endblock %}