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?
Jinja2 filter is something we use to transform data held in variables. We apply filters by placing pipe symbol | after the variable followed by name of the filter. Filters can change the look and format of the source data, or even generate new data derived from the input values.
Built into Jinja2 is functionality for building a 'base' template file and building off of it. This is known in Jinja2 functionality as “extending” a file. Files extend when they use the keyword block to define a section. The keyword endblock closes out a section.
You can use filter sections:
{% block content %}
{% filter upper %}
Here is some content that will be rendered in upper case.
{% endfilter %}
{% endblock %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With