Welcome Guest, Not a member yet? Register   Sign In
Best practice for meta data/css/js etc

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:

$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',
    'js'            => array('common.css')

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

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.

There's definitely a better way.

What you need to do is use template.

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!

Theme © iAndrew 2016 - Forum software by © MyBB