Symfony2 Path to image in twig template

前端 未结 3 684
长情又很酷
长情又很酷 2021-01-03 20:40

I store img in Acme/DemoBundle/Resources/public/img/weather_icon/blizzard.gif I want to put this img in my template so I did



        
3条回答
  •  借酒劲吻你
    2021-01-03 21:04

    Assetic solution: You will get better performance with assetic as opposed to asset.

    directory structure for example:

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

    project structure for example:

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

    in yourhtml.html.twig call:

    {% image '@AppBundle/Resources/public/images/yourimage.png' %}
                        Example
                    {% endimage %}
    

    NOTE:

    This is providing you install assetic bundle which can be set in composer.json of the project as such:

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

    google for more instruction on installing assetic bundle symfony2.

    that is it.

    source:

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

提交回复
热议问题