One minute
Symfony3 Importing JS / CSS assets from a bundle in your custom templates
👴 Careful You’re reading an old article ! Some links might be broken and content may be outdated
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 :
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 :
```html
<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.
Read other posts