pongo2 icon indicating copy to clipboard operation
pongo2 copied to clipboard

using existing Jinja templates with pongo2

Open kgeipel-retail7 opened this issue 4 years ago • 1 comments
trafficstars

At first, it saw like I could simply use my existing templates from Ansible projects in golang using the pongo2 template engine. But i can't figure out how to template nested elements like the following one:

Example from Ansible template (upper case elements are template variables): "{{ ('http://' + NAMESPACE + '-repo.' + NAMESPACE + ':3004') | b64encode }}",

The b64encode function I got running after a little research, but the main problem is that the concatenation of template variables and raw strings doesn't work like expected. The above example result in pongo2 to a parsing error

[Error (where: parser) in | Line 8 Col 88 near '|'] '}}' expected

So maybe there is a possibility to use pongo2 the way I need it, I appreciate any help with that.

kgeipel-retail7 avatar Dec 17 '20 12:12 kgeipel-retail7

If you are looking for a way to process Jinja2 templates with Go, have a look at https://github.com/noirbizarre/gonja. The documentation is not up to date, but the above mentioned string concatenation (using the ~ operator) as well as filters with Jinja2 syntax (e.g. {{ foo | default("bar") }} does work.

breml avatar Jun 18 '21 11:06 breml