CodeIgniter Forums

Full Version: Clean Javascript integration in CI4
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I use a lot of JavaScript on my sites, and with CI3, it is always a problem to add the JS in the views. 
  • I'm sending a list of JS files from the controller,
  • Looping the list to add the JS files in the views
  • Doing it twice if JS files are loaded in the head and in the body section
  • Creating another view if some PHP variables must be sent to JS

It would be nice in future versions to add something allowing smart integration of JS files in the view. I'm not sure what should be done, neither how it should be done, but with CI3, I don't have the feeling of doing something very nice.
I don't know if this will ever be a part of the framework itself, but check out this module that does what you are requesting:

https://github.com/tattersoftware/codeigniter4-assets
(01-07-2020, 12:38 PM)MGatner Wrote: [ -> ]I don't know if this will ever be a part of the framework itself, but check out this module that does what you are requesting:

https://github.com/tattersoftware/codeigniter4-assets

Thank you. I don't understand clearly what assets are. But it sounds nice. I'll have a deeper look at it in when CI4 will be ready for production.
Assets are typically JavaScript scripts, CSS stylesheet files, and images (though they could be a lot of things). That assets module covers JavaScript which seems to be your area of interest.