I have jinja template file with variable names like x.y.z (like java package names). Then I'm using Python envtpl to generate actual config file from jinja template file using envtpl.process_file. But it errors out saying 'x' is undefined. I know in jinja dot means something else so how do I escape it so that envtpl understands that 'x.y.z' is a variable name not just 'x'.
template file for example:
foo = "{{ x.y.z | default("abc") }}"
bar = "{{ a.b.c | default("123") }}"
If someone is still interested in this, this worked for me:
/* model */
...
some_function('some.value')
...
{# macro #}
{% macro some_function(value) %}
{% set data = {{ "'"+value+"'" }} %}
{{ data }}
{% endmacro %}
OR
{# macro #}
{% macro some_function(value) %}
{% set data = {{ "'%s'" % value }} %}
{{ data }}
{% endmacro %}
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