Jinja: Include template and apply filter

Created on 5 Aug 2014  路  1Comment  路  Source: pallets/jinja

Hi,

I searched almost everywhere but couldn't find an answer on how to include a template and apply filter to it.
I have created toJson filter and trying to include text from another template and apply filter to it. I tried this
{% include 'another_template.txt'|jsonify %} -- this returns another_template not found error

If I remove jsonify then it works but doesn't convert my text to json.

Ritesh

Most helpful comment

This is resolved using macros. Here is an example:

{% macro parentLoader() %}
{% include "LogEventToFile/HiveToLocal.txt" %}
{% endmacro %}

{
"message": {{ parentLoader()|trim|jsonify }},
"runtime": {{runtime}}
}

>All comments

This is resolved using macros. Here is an example:

{% macro parentLoader() %}
{% include "LogEventToFile/HiveToLocal.txt" %}
{% endmacro %}

{
"message": {{ parentLoader()|trim|jsonify }},
"runtime": {{runtime}}
}

Was this page helpful?
0 / 5 - 0 ratings