Symfony2 Assetic 动态图像包含在 Twig 中
我想使用 Twig 和 Assetic 加载文章的特定缩略图。这是不起作用的代码:
在配置和参数中:
thumbnail_dir="/Resources/public/images/article_thumbs"
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
globals:
thumbnail_dir: %thumbnail_dir%
在树枝文件中:
{% image '@MyMainBundle' ~ thumbnail_dir ~ '/' ~ id ~ '/' ~ article.thumbnailFile %}
<img src="{{ asset_url }}"
alt="{{ article.title }}" />
{% endimage %}
所以基本上我有图像存储在 /Resources/public/images/article_thumbs/{ID}/{FILE.ext}
我想要获取 Twig 中特定文章的这些内容。我怎样才能做到这一点?
编辑: 为什么我不把它们放在 web 文件夹中?
我想我曾经在某个时候考虑过使用 Assetic 过滤器,但我认为确实没有必要。
我暂时将它们存储在 web 文件夹中。
因此,如果我制作 thumbnail_dir="/images/article_thumbs"
并将其放入网络目录中,我只需说 {{ asset(thumbnail_dir ~ '/' ~ id ~ '/' ~ Article.thumbnailFile ) }}
在树枝中?
I want to load a specific thumbnail for an article using Twig and Assetic. Here is the code that doesn't work:
in config and params:
thumbnail_dir="/Resources/public/images/article_thumbs"
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
globals:
thumbnail_dir: %thumbnail_dir%
In the twig file:
{% image '@MyMainBundle' ~ thumbnail_dir ~ '/' ~ id ~ '/' ~ article.thumbnailFile %}
<img src="{{ asset_url }}"
alt="{{ article.title }}" />
{% endimage %}
So basically I have images I'm storing in /Resources/public/images/article_thumbs/{ID}/{FILE.ext}
I want to get those for a specific article in Twig. How can I achieve that?
EDIT:
Why am I not putting them in the web folder?
I guess I had thought about using Assetic filters at some point, but I suppose there is really no need.
I'll just store them in the web folder for now.
So if I make thumbnail_dir="/images/article_thumbs"
and put that in the web dir, Do I just say {{ asset( thumbnail_dir ~ '/' ~ id ~ '/' ~ article.thumbnailFile ) }}
in twig?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 Kriswallsmith 的说法,使用 assetic 是不可能实现这一点的。
https://github.com/kriswallsmith/assetic/issues/60
如果我理解正确的话:
由于 assetic 不会渲染 Twig,因此不会读取变量。
According to Kriswallsmith this is not possible using assetic.
https://github.com/kriswallsmith/assetic/issues/60
If I understood correctly:
Since assetic does not render the Twig the variable is not being read.