1
votes

I need to escape some JS twig-like variables in a twig template, but I couldn't find anything about how to do that.

This variables are used in a js templating plugin that uses the same pattern as twig for variables

tooltipFormat: '<span style="color: {{color}}">&#9679;</span> {{offset:names}}: {{value}}',

which is causing the twig rendering to fail

Unexpected token "punctuation" of value ":" ("end of print statement" expected) in "path/to/template.twig" at line 116

Thanks in advance for any help.

1
Is {{color}} twig's or JavaScript's now? - Praveen Kumar Purushothaman
change the twig delimiters. stackoverflow.com/questions/25002996/… - Rooneyl
They are all javascript... - Anderson Ivan Witzke
Changing the twig delimiters wouldn't solve my problem.. in fact, will just create bigger ones, since the application I'm using this code is in the final stages of development and I would have to change every twig file to the new patterns... - Anderson Ivan Witzke

1 Answers

0
votes

You can use the verbatim tag, as example, suppose you want to don't process all the code you posted, you can act in this manner:

<span style="color: {{color}}">&#9679;</span>{% verbatim %} {{offset:names}}: {{value}}',{% endverbatim %}

This will dump the value of the color variable and dump the code surrounded by the verbatim tag

hope this help