Dziamid Dziamid - 2 months ago 9
Twig Question

Twig: prevent parsing of client-side templates

I need to output a portion of client-side handlebars templates, which has tags similar to twig's 'say' tags:

<script type="text/x-handlebars">
{{#view App.MyView}}
<h1>Hello world!</h1>
{{/view}}
</script>


And twig attempts to parse these templates. How do I prevent it? Is it possible to mark a section of a template as plain text?

Answer

There is raw tag for this purpose:

<script type="text/x-handlebars">
  {% raw %}
    {{#view App.MyView}}
      <h1>Hello world!</h1>
    {{/view}}
  {% endraw %}
</script>

Update

As raw tag is deprecated use verbatim instead.

Comments