Jump to content

$config->scripts, how to add scripts at the top and the bottom of template?


NorbertH
 Share

Recommended Posts

If i have a template that requires scripts added in head  and at the end of body.

Do you have any idea how to handle this whith $config->scripts.

Another point is how to handle if its necessary to add not just files but small scripts that need to be added at the head or bottom.(like google analytics).

Is there something like :

$config->scripts-bottom

$config->scripts-direct

Maybe there is a way to make such an array, besides from silmply creating the var.

Link to comment
Share on other sites

You could make your own:

// a filename array for scripts in the head (make the name you wish)
$config->headScripts = new FilenameArray();

// a filename array for scripts in the bottom (make the name you wish)
$config->bottomScripts = new FilenameArray();

// add scripts to the head FilenameArray
$config->headScripts->append('/your/wished/path/head.js');

// add scripts to the bottom FilenameArray
$config->bottomScripts->append('/your/wished/path/bottom.js');
  • Like 6
Link to comment
Share on other sites

Is there something against abusing it this way ?

// a filename array abused  for plain scripts 
$config->headScripts = new FilenameArray();

// add scripts to the  FilenameArray
$config->headScripts->append("jQuery('a.gallery').colorbox(); ");

// this one s added in main.php
<? foreach($config->headScripts->unique() as $script) echo "\n\t<script type='text/javascript'>$script</script>";?>

Link to comment
Share on other sites

  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...