Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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:

$this->assets->collection('header')->addJs('js/jquery.js')->addJs('js/bootstrap.min.js');

And in your volt template:

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

This should work



18.8k

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.

$this->assets->addJs('js/filename.js')

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



10.1k
Accepted
answer

That will do the job ;)

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

@chebureque, Thanks to my problem was resolved

That will do the job ;)

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