Search code examples
phpsymfonypolymertwig

How to make Twig ignore curly braces meant for Polymer?


I am trying to use Polymer in a Twig template. But I am facing this issue when binding the data. I am not able to use {{ }}, because Twig considers this as its echo delimiters.

How can we make Twig ignore the curly braces in this piece of code?

  <iron-ajax auto url="http://demo.vaadin.com/demo-data/1.0/people" handle-as="json" last-response="{{peopleResponse}}"></iron-ajax>
  <vaadin-grid items="{{peopleResponse.result}}">
    <table>
      <colgroup>
        <col name="firstName"/>
        <col name="lastName"/>
        <col name="email"/>
        <col name="address.phone"/>
      </colgroup>
    </table>
  </vaadin-grid>


Solution

  • You can 'escape' the double curly braces by using {{ '{{peopleResponse}}' }}.

    Alternatively, you can change the Twig echo delimiters:

    $env->setLexer(new Twig_Lexer($env, [
        'tag_variable' => ['{[', ']}'],  // Now you should use {[ ]} for twig
    ]));