While implementing the PrestaImage bundle in a Symfony 3 project, I had to include the assets of the bundle in my custom template file. I had first copy / paste manually the files but I thought it was not an easy / clean way to maintain these files.

Install the assets in the public web folder

I used the magnificient CLI of Symfony :

php bin/console assets:install web

This command will :

  1. Copy the assets files – placed under vendor/YOUR_BUNDLE/Resources/public/js or vendor/YOUR_BUNDLE/Resources/public/css
  2. Create two folders for JS and CSS assets under web/bundles/<your_bundle>/

Calling the assets in the template

Then you will be able to call the assets in your custom twig template using :

<link rel="stylesheet" href="{{ asset('bundles/YOUR_BUNDLE/css/YOUR_ASSET_NAME.css') }}" />

I was surprised that there were no way to directly call the files without copying them, it would save some time and disk space.

Leave a Reply

Your email address will not be published. Required fields are marked *