【问题标题】:Twig concatenation in assets资产中的 Twig 连接
【发布时间】:2015-01-24 03:52:08
【问题描述】:

这很好用:

   {% image '@TestBundle/Resources/pic2/image.jpg' %} 
       <img src="{{ asset_url }}" alt="Example" />
   {% endimage %}

但我需要通过显示上传图像的名称而不是 image.jpg 来使其更具动态性。我需要以某种方式将资产与{{ entity.picture }}

有什么方法可以在 twig 中做到这一点而不会出错?

{% image '@TestBundle/Resources/pic2/' . {{ entity.picture }} %}  

【问题讨论】:

  • @Chausser,不是真的。我在打开这个帖子之前检查了那个帖子,还有别的东西。我需要为资产完成连接。无论如何,这对我不起作用。

标签: php symfony twig


【解决方案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 }}">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多