2017-06-22 83 views
2

我好心寻求帮助,这样的细枝模板中显示动态图像URL:如何使用Twig显示动态图像URL?

// non-working pseudocode, myImageFilename contains image filename 
{% image '@AppBundle/Resources/public/images/' + myImageFilename %} 
    <img src="{{ asset_url }}" /> 
{% endimage %} 

但枝条只允许静态的文件名,这样(从资料为准)。我已经试过concatinator ~

{% image '@AppBundle/Resources/public/images/' ~ myImageFilename %} 

,但它也不起作用,

{% image '@AppBundle/Resources/public/images/example.jpg' %} 
    <img src="{{ asset_url }}" alt="Example"/> 
{% endimage %} 

是否有使用动态图像的URL与此嫩枝图像逻辑成为了可能?

回答

3

你的形象因为,我不认为这是有可能做它。这背后的原因是Assetic预先运行以转储资产​​。

它通过这种方式是可能的:

<img src="{{ asset('bundles/appbundle/Resources/public/images/'~myImageFilename }}" alt="Example"/> 
1

无法从浏览器客户端acceed bundle目录(的.htaccess所有否认),你现在加载从./web/目录而不是