Welcome Guest, Not a member yet? Register   Sign In
javascript and template division

I am developing an application with codigniter. I have divided my template into 5 files.

meta.php, header.php, maincontents.php, sidenavigation.php, footer.php

is this division right? Where do I write my javascript or jquery functions as different controllers has different functions and these functions include different jquery plugins.
If i write my scripts in meta.php then every page will load that script, that i think is a bad thing.

confused !!

About the division: whatever works for you is right! I don't think there is any one "true solution".

About the scripts: I would put the functions in separate .js files. Then I would tell the 'meta' view (which probably means the 'head' part of your html document) which .js files to load. For instance by passing an array of js filenames.

In meta.php:

$js = array('jquery.js',

foreach($js as $file) {
    echo '<script type="text/javascript" src="jscripts/' . $file . '"></script>' . "\n";

And yes, whatever works for you is right Smile

Thanks both of you .. thats what i was thinking but now i can do this with confidence. Smile

Theme © iAndrew 2016 - Forum software by © MyBB