Question

While we are using Assetic with Twig templating, we want to delay the actual processing until the last moment for various reasons. So instead of using the javascripts, css tags of assetic we created something like this

{{ add_asset (['public/js/prototype-handler.js', 'public/js/shipping-method.js'], 'js') }}

Anyhow, the idea is that at the end of the response event we will process and inject all assets to the content. However, right now I'm stuck at how to add these assets to assetic so they can be processed and returned with the result file(s).

I have checked some other bundles and what they are doing right now is to render the assets via twig like this:

AssetManagementBundle

However, it doesn't seem to be an optimal approach to this. I wonder if there is a better way or not?

Was it helpful?

Solution

For people who may encounter this same need, you want to use createAsset of the AssetFactory.

Then you can loop through the created assets and do what you want with them.

For more information and working code, please check our bundle here

OTHER TIPS

I'm not sure to completely understand your needs but you could be interested by the AsseticInjectorBundle, it allows you to tag your resources files in a configuration file and add it by adding the tag where you want in your assetic markup, in your layout. I don't think dealing with resources in php is a great idea and it's better to do this directly in your layout coupled with some configuration file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top