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.

js-files into the view folder

I have a js file named script.js in the asset folder of my web application. But it goes bigger and bigger, so I want to split it into the different controler parts. For example I want to put all scripts that handle user actions in a file named user.js. And I want to put it into the folder view->user->user.js

The problem is that I don't know where to load these script. One solution may be to load it in the different views. (e.g. index.volt) But there is the problem that I have to change all views to include the js files.

I search for a solution that I can dynamicly load the scripts before accessing the controller action. Are there any ideas?

PS: I know that this system is slower than one script file, but it is more comfortable to have more little files when developing the application. When publishing this software I will use one script file for better performance.

Thank you for reading! :)



1.7k
Accepted
answer

I found this. Klick I think this is very helpful.

Yes you can use the assets manager to add whatever resources you want using your base controller and any other controller or even action.