这很好用:
{% image '@TestBundle/Resources/pic2/image.jpg' %}
<img src="{{ asset_url }}" alt="Example" />
{% endimage %}
但我需要通过显示上传图片的名称而不是image.jpg来使其更具动态性。我需要以某种方式将资产与{{ entity.picture }}
有没有办法在树枝上做这个,当然没有出错?
{% image '@TestBundle/Resources/pic2/' . {{ entity.picture }} %}
答案 0 :(得分:1)
你可以试试这个:
// config.yml add a global variable (Or just assign the path from the controller)
twig:
globals:
imagepath: "your/path/to/thepictures/"
由于此图片用于assets optimization:
,因此我不会这样做{% image {{ imagepath ~ entity.picture }} %}
所以替代方案可以是:
<img src="{{ imagepath ~ entity.picture }}">