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

[eluser]mysterious[/eluser]
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 !!
#2

[eluser]mddd[/eluser]
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.
#3

[eluser]JoostV[/eluser]
In meta.php:

Code:
$js = array('jquery.js',
            'autocomplete.js',
            'lightbox.js');

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

And yes, whatever works for you is right Smile
#4

[eluser]mysterious[/eluser]
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