We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Add assets in Volt

Is it possible to add an asset from a Volt template? Something like:

{% assets.addJs('js/filename.js') %}

Or do I need to do it with PHP code?

edited Oct '14

Check the docs for more info -> https://github.com/phalcon/docs/blob/master/en/reference/assets.rst In your controller:


And in your volt template:

{{ this.assets.outputJs('header') }}

This should work


No guys, I don't want to output tags! What I need is to add a file to assets from a template. I can do that with the following PHP code both from the controller and from the template, but so far I couldn't find a way to use Volt. The case for that would be if a front-end developer or designer needs to include a JavaScript file for that particular view. It would be nice to have something in Volt that would allow for that.


I'm looking for the equivalent Volt code of the previous PHP code ;)


That will do the job ;)

{% do assets.addJs('js/filename.js') %}

@chebureque, Thanks to my problem was resolved

That will do the job ;)

{% do assets.addJs('js/filename.js') %}