我添加圖片了assetic這樣的:短語法Assetic樹枝圖像功能
{% image '@MyBundle/Resources/public/img/name.png' %}
<img src="{{ asset_url }}"/>
{% endimage %}
工作正常,我,但我想少寫,所以我tryed以創建像在Symfony2的樹枝功能實況。但我不使用任何過濾器:
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [MyBundle]
#java: /usr/bin/java
filters:
cssrewrite: ~
twig:
functions:
timg: ~
但是如果我現在使用它:
<img src="{{ timg('@MyBundle/Resources/public/img/name.png') }}" />
我得到異常:
An exception has been thrown during the compilation of a template ("Catchable Fatal Error: Argument 3 passed to Twig_Node_Expression_GetAttr::__construct() must be an instance of Twig_Node_Expression_Array, instance of Twig_Node given, called in C:\wamp2\www\symfony\vendor\symfony\assetic-bundle\Symfony\Bundle\AsseticBundle\Twig\AsseticNodeVisitor.php on line 66 and defined in C:\wamp2\www\symfony\vendor\twig\twig\lib\Twig\Node\Expression\GetAttr.php line 14") in "::top.html.twig".
任何想法?也許我不能使用沒有過濾器的簡短語法的函數?
http://symfony.com/doc/current/cookbook/assetic/jpeg_optimize.html#shorter-syntax-twig-function在這裏我得到了這個短sintax的想法 – degressor