Welcome Guest, Not a member yet? Register   Sign In
How to load selective JS and CSS in individual views
#4

[eluser]darkhouse[/eluser]
I run into this a lot, so I actually wrote a library (that I autoload) that allows me to manage js and css files per controller. I called it External.

Code:
//In my controller I can do this
$this->external->set_js('js/somefile.js');
$this->external->set_js('alert("testing");', 'custom');

//or I can do this
$this->external->set_js(array('js/somefile.js', 'js/someotherfile.js'));

//or I can even do this
$this->external->set_js(array(
     'js/somefile.js',
     'js/someotherfile.js',
     array('alert("testing");', 'custom')
));

And css is setup the same way, but with a few more options like for media="print", ie specific and ie6 specific.

Then in the header view, I just have this:

Code:
$this->external->run();

I just have one more feature to add to it, which is a config file for autoloading certain files so you don't have to put them directly in the view, or load them in every controller. I was also thinking about having groups setup in the config based on the uri string, so that if you were in, say, something like 'admin/whatever' and you had a group setup for 'admin', any controller in the admin would auto load those files. I normally have different css for my admin areas than for the front end.

I know there are template systems, but if anyone's interested in this, let me know and I'll send it once I have the config system done.


Messages In This Thread
How to load selective JS and CSS in individual views - by El Forum - 01-03-2009, 05:08 PM
How to load selective JS and CSS in individual views - by El Forum - 01-04-2009, 12:33 AM
How to load selective JS and CSS in individual views - by El Forum - 01-04-2009, 01:24 AM
How to load selective JS and CSS in individual views - by El Forum - 01-04-2009, 02:56 AM
How to load selective JS and CSS in individual views - by El Forum - 01-04-2009, 11:06 AM
How to load selective JS and CSS in individual views - by El Forum - 01-04-2009, 11:09 AM
How to load selective JS and CSS in individual views - by El Forum - 01-04-2009, 11:15 AM
How to load selective JS and CSS in individual views - by El Forum - 01-04-2009, 11:17 AM
How to load selective JS and CSS in individual views - by El Forum - 01-04-2009, 01:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB