如何让 Twig 忽略用于 Polymer 的花括号?

san*_*kar 2 php symfony twig polymer

我正在尝试在 Twig 模板中使用 Polymer。但是我在绑定数据时遇到了这个问题。我无法使用 {{ }},因为 Twig 将其视为其回声分隔符。

我们如何让 Twig 忽略这段代码中的花括号?

  <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>
Run Code Online (Sandbox Code Playgroud)

Pet*_*ete 5

您可以使用 .escape 来“转义”双花括号{{ '{{peopleResponse}}' }}

或者,您可以更改 Twig 回声分隔符:

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