Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the default double curly braces delimiter in polymer?

I'd like to use polymer in a Python/Flask project. Flask uses the Jinja2 templating engine, which also uses the double curly braces {{}} as delimiters.

Escaping braces in Jinja2 is possible, but it results in very ugly and unreadable code I'd like to avoid.

Although it's also possible to change the delimiters in Jinja2, I'd rather change them in Polymer, because we already use some Jinja2 templates in the project.

So the question is, is it possible to change the delimiters in Polymer, and if so, how do we go about that?

Thanks

like image 325
Erik Oosterwaal Avatar asked Nov 18 '15 08:11

Erik Oosterwaal


1 Answers

In the templates module, when initializing the jinja2 environment you can pass optional start/stop delimiters:

environment = jinja2.Environment(loader=loader, trim_blocks=True,block_start_string='@@',block_end_string='@@',variable_start_string='@=', variable_end_string='=@')

would change {% statement %} to @@ statement @@ and {{ var }} into @= var =@.

Make it a config option and only pass if set, otherwise jinja will use its own defaults.

credits: Brian Coca Link

like image 176
Vignesh Krishnan Avatar answered Nov 14 '22 22:11

Vignesh Krishnan