AngularJS-Twig conflict with double curly braces

前端 未结 11 675
孤独总比滥情好
孤独总比滥情好 2020-11-22 14:39

As you know, both angular and twig has common control construction - double curly braces. How can I change default value of Angular?

I know that I can do it in Twig,

相关标签:
11条回答
  • 2020-11-22 15:19

    This is a compiled version of the best answers and a example for verbatim blocks:

    For single insertions, use:

    {{ '{{model}}' }}
    

    or if you use a twig variable

    {{ '{{' ~ twigVariableWitModelName ~ '}}' }}
    

    Verbatim, is very elegant and readable for several angular variables:

    <table ng-table>
        {% verbatim %}
            <tr ng-repeat="user in $data">
            <td data-title="'Name'">{{user.name}}</td>
            <td data-title="'Age'">{{user.age}}</td>
            </tr>
        {% endverbatim %}
    </table>
    
    0 讨论(0)
  • 2020-11-22 15:20

    You can create a function in twig to surround your angular directives, so like instead of going ...

    {{"angular"}}

    you go ...

    {{angular_parser("angular stuff here output curlies around it")}}

    0 讨论(0)
  • 2020-11-22 15:22

    I like @pabloRN, but I would prefer to use span instead of p, because for me p will add line to the result.

    I will use this:

    <span ng-bind="yourName"></span>
    

    I also use aText with the cursor inside the double quote so I don't have to rewrite the whole thing over and over again.

    0 讨论(0)
  • 2020-11-22 15:24

    You can use \{{product.name}} to get the expression ignored by Handlebars and used by Angular instead.

    0 讨论(0)
  • 2020-11-22 15:25

    As mentioned in similar question about Django and AngularJS, trick with changing default symbols (in Twig or AngularJS) can provide incompatibility with third-party software, which will use these symbols. So best advice I found in google: https://groups.google.com/d/msg/symfony2/kyebufz4M00/8VhF1KWsSAEJ

    TwigBundle does not provide a configuration for the lexer delimiters as changing them would forbid you to use any templates provided by shared bundles (including the exception templates provided by TwigBundle itself).

    However, you could use the raw tag around your angular templates to avoid the pain of escaping all curly braces: http://twig.sensiolabs.org/doc/tags/raw.html -- Christophe | Stof

    Tag was renamed to verbatim

    0 讨论(0)
  • 2020-11-22 15:26

    If you're not interested in changing the template tags of the existing angular syntax which would require some confusing rewriting of your existing angular templates.

    One can just use the twig template tags with angular tags like so:

    {% verbatim %}{{yourName}}{% endverbatim %}
    

    Found this on another similar thread answer: Angularjs on a symfony2 application

    0 讨论(0)
提交回复
热议问题