symfony - Override an image from a bundle -


i have this:

shopbundle   controller   resources     public       images         marker.png     views       default         index.html.twig 

in index.html.twig, i'd have this

<img src="{{ asset("images/marker.png") }}"/> 

and i'd love people using bundle want use own marker.png have build bundle inheriting mine , place image following files structure:

myshopbundle   resources     public       images         marker.png 

is there simple way in symfony2 ? need seems simple can't believe didn't find answers already.

so,

  • how include image asset in bundle template bundle resources directory ? did ./apps/hfr/console assets:install web template not print right url (/images/marker.png instead of /bundles/shopbundle/resources/public/images/png)

  • is possible override way want or did lost way ?

solution:

use @ syntax ...

{% image '@vendormyshopbundlebundle/resources/public/images/example.jpg'     output='/images/example.jpg' %}     <img src="{{ asset_url }}" alt="example"/> {% endimage %} 

please note vendor/yourbundle/resources/public not accessible web server normally.

the assets:install command therefore copy assets web/bundles/vendoryourbundle

the {{ asset('path/to/asset.jpg') }} function adjust url of asset if youre using dev environment:

 http://hostname/app_dev.php  

from

/path/to/asset.jpg  

to

/app_dev.php/to/asset.jpg 

[edit]

if want more control on assets maybe consider using asset collections.

you can configure them follows:

# app/resources/config/config.yml  assetic:     [...]     assets:         css_bootstrap:             inputs:                 -  %kernel.root_dir%/../src/vendor/yourbundle/resources/public/twitter-bootstrap/less/bootstrap.less                 - [...]             filters:                 - lessphp                 - [...]             output: css/bootstrap.css           my_image:             inputs:                  - %kernel.root_dir%/../path/to/image.png             filters:                 - optipng             output: images/image-with-new-name.png 

and use them afterwards in template this:

{% stylesheets '@css_bootstrap' %}     <link rel="stylesheet" type="text/css" href="{{ asset_url }}"> {% endstylesheets %} 

i not sure right if assetic/assets/packagename/inputs configuration array supports @vendoryourbundle syntax aswell , uses bundle inheritance though.

addition:

before can use these packages have use console command:

php app/console assetic:dump 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -