Sunday, July 03, 2011

Codeigniter library: Autoload Assets


I've created this library to make easy using css or js files with views/templates.
Its use it is very easy, although with a template it is more useful.

descripción en español


How it works

This library find css/js files with same name that controller and view, and load these files (if exists):

  • controller.css
  • controller_view.css
  • controller.js
  • controller_view.js
You only add the file/s in the corresponding directory, and the library loads automatically it. ¿Easy no?




Configuration

You can configure directory names in config.php file:
$config['assets_dir'] = 'pub'; //Default is pub
$config['assets_css_dir'] = 'css'; //Default is css
$config['assets_js_dir'] = 'js'; //Default is js
Note: assets_css_dir and assets_js_dir works into assets_dir directory
So the file structure would see like this:
/pub
/pub/css
/pub/js
Note: Don't forget create directories.



Calling to the Library

In view/template into '<'head'>'  tag add this code:

'<'?php Autoload_assets::get();?'>'

I hope it will be useful.

Download Codeigniter Assets

Help to use libraries here

No comments: