2

我想为使用 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 ) }}在树枝中说吗?

4

1 回答 1

3

根据 Kriswallsmith 的说法,使用资产是不可能的。

https://github.com/kriswallsmith/assetic/issues/60

如果我理解正确:由于assetic 不会呈现Twig,因此不会读取变量。

于 2013-04-18T09:07:24.590 回答