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}}">●</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.
Advertisement
Answer
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}}">●</span>{% verbatim %} {{offset:names}}: {{value}}',{% endverbatim %}
This will dump the value of the color variable and dump the code surrounded by the verbatim tag