-->

Symfony2的路径图像在树枝模板(Symfony2 Path to image in twig

2019-09-02 01:36发布

我存储中IMG Acme/DemoBundle/Resources/public/img/weather_icon/blizzard.gif我想把这个IMG在我的模板,所以我做

<img src="{{ asset('bundles/acmedemo/img/weather_icons/blizzard.gif') }}" />

<img src="{{ asset('..img/weather_icons/blizzard.gif') }}"  />

而这个我以前不工作。 我做资产:安装和assetic:转储

解决它的工作

<img src="{{ asset('img/weather_icons/Blizzard.gif') }}" alt="Symfony!" />

Answer 1:

请试试这个

<img src="{{ asset('bundles/acmedemo/img/weather_icons/blizzard.gif') }}" />

你应该istall你的资产转移到web目录与命令

app/console assets:install web


Answer 2:

您可以使用捆绑的图像:

{% image '@CoreBundle/Resources/public/images/your-image.jpg'  output="images/your-image.jpg" %}
<img src="{{ asset_url }}" width="100%" height="100%" alt="my alt of image" class="pull-left">
{% endimage %}


Answer 3:

Assetic解决方案:您将获得更好的性能与assetic,而不是资产。

例如目录结构:

C:\xampp\htdocs\yourproject\src\AppBundle\Resources\public\images\yourimage.png

例如项目结构:

yourproject\src\AppBundle\Resources\public\images\yourimage.png

在yourhtml.html.twig电话:

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

注意:

这是为您提供安装,可以在项目中这样的composer.json设置assetic包:

"require": {
"php": ">=5.3.3",
"sensio/framework-extra-bundle": "~3.0",
"symfony/assetic-bundle": "~2.6", },

谷歌上安装assetic束Symfony2的更多指令。

这就对了。

资源:

http://symfony.com/doc/2.7/cookbook/assetic/asset_management.html#cookbook-assetic-cssrewrite



文章来源: Symfony2 Path to image in twig template