CodeIgniter Forums
Best practice for meta data/css/js etc - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Best practice for meta data/css/js etc (/showthread.php?tid=33586)



Best practice for meta data/css/js etc - El Forum - 09-01-2010

[eluser]AJR[/eluser]
Hi all,

Fairly new to CI and after working with it a while i've been doing the following to load various css/js files into my header view from within the controllers. I'm also using this method for meta keywords, page titles etc:

Code:
$this->header = array(
    'page'          => strtolower(get_class($this)),
    'title'         => 'Page title',
    'keywords'      => 'key, words, keywords',
    'description'   => 'A lovely description',
    'h1'            => 'Page heading',
    'css'           => array('javascript.js',
                             'another.js'),
    'js'            => array('common.css')
);

$this->load->view('templates/header', $this->header);
$this->load->view('some/page', $this->data);
$this->load->view('templates/footer');

My header view would then load the relevent js and css files and insert the meta data into the <head> tags.

While this seems like the obvious way to do things, I don't like the idea of having whats effectively content in my controllers. It also sometimes gets repeated and makes my controllers a bit messy.

How do you all manage this? There must be a better way to do this? Language files? Config files?

Thanks for the advice.


Best practice for meta data/css/js etc - El Forum - 09-01-2010

[eluser]josen[/eluser]
There's definitely a better way.

What you need to do is use template.
http://williamsconcepts.com/ci/codeigniter/libraries/template/index.html

You can code your template.php to load all the necessary js and css files.
That way, you will need to load only the main content from your Controller instead of loading all the headers, footers, js, css, etc.

It's much more elegant and easier to maintain.
Good luck!