[英]How to print an AngularJS variable out as a link in a Symfony2 project
我试图在用AngularJS获取值的同时打印symfony2中的链接。 我在花括号方面遇到问题。
例如:
<div id="columns"> <div class="block" ng-repeat = "tip in tips"> <img src="{{' {{ tip.imageDocument.webPath }}'}}" alt=""> <div class="detail"> <h2>{{ '{{ tip.title }}' }} {{ '{{ tip.id }}' }}</h2> <p>{{ '{{ tip.introduction }}'}}</p> <a href="./tips/{{'{{ tip.id }}'}}" class="button">{% trans %}Read more{% endtrans %}</a> </div> </div> </div>
我发现如果在尖括号“ {{variable'}}”周围加上花括号,它会起作用
像这样
{{ '{{ variable }}' }}
但这对我来说似乎不对。 此外,该链接不起作用。 它被打印为%7B%7B%20tip.id%20%7D%7D,这显然是因为大括号。
任何人?
谢谢
您是否尝试过{{ '{{ variable }}' | raw }}
{{ '{{ variable }}' | raw }}
? 似乎在Twig配置中启用了转义。 默认情况下。
编辑 :好的,看来实际发生的情况是浏览器自动“大括号”大括号。 我认为问题不在于Twig,实际上是Angular.js。 使用Angular时不应使用ng-href
而应使用ng-href
。
您是否试图摆脱内在的花括号?
<div id="columns">
<div class="block" ng-repeat = "tip in tips">
<img src="{{' \{\{ tip.imageDocument.webPath \}\}'}}" alt="">
<div class="detail">
<h2>{{ '\{\{ tip.title \}\}' }} {{ '\{\{ tip.id \}\}' }}</h2>
<p>{{ '\{\{ tip.introduction \}\}'}}</p>
<a href="./tips/{{'\{\{ tip.id \}\}'}}" class="button">{% trans %}Read more{% endtrans %}</a>
</div>
</div>
</div>
这很丑陋,但也许可以为您提供帮助。
无论如何,要显示角度的变量,请使用verbatim
标记。
举个例子:
{% verbatim %} {{ tip.title }}{% endverbatim %}
现在{{ tip.title }}
不会被twig解析,而是由angularjs解析。
您应该使用{%verbatim%}来摆脱TWIG的curly ,并为src和href使用ng- *属性,以允许AngularJS很好地解析它,如下所示:
<div id="columns">
<div class="block" ng-repeat="tip in tips">
<img ng-src="{% verbatim %}{{ tip.imageDocument.webPath }}{% endverbatim %}" alt="">
<div class="detail">
<h2>{% verbatim %}{{ tip.title + ' ' + tip.id }}{% endverbatim %}</h2>
<p>{% verbatim %}{{ tip.introduction }}{% endverbatim %}</p>
<a ng-href="./tips/{% verbatim %}{{ tip.id }}{% endverbatim %}" class="button">
{% trans %}Read more{% endtrans %}
</a>
</div>
</div>
</div>
有关ng- *属性的更多示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.