Hi,
I am trying to figure out a strange situation in Drupal 5.6
If I use the following:
<?php drupal_add_js( '$(document).ready(function(){ $("p").fadeIn("slow"); });', 'inline'); ?>
This does not get added to the header automatically.
If I add:
print drupal_get_js() it then inserts all the scripts at the point where it finds the code (just after body) in page.tpl.php
The only solution is to substitute print $scripts with print $drupal_get_js() in the head section.
Now I don't mind doing that put it would be good to know why this does not work or if anyone else encountered this.
This is a clean Drupal 5.6 installation with the Garland theme...
Best,
Ronald
Ronald Ashri wrote:
Hi,
I am trying to figure out a strange situation in Drupal 5.6
If I use the following:
<?php drupal_add_js( '$(document).ready(function(){ $("p").fadeIn("slow"); });', 'inline'); ?>
This does not get added to the header automatically.
If I add:
print drupal_get_js() it then inserts all the scripts at the point where it finds the code (just after body) in page.tpl.php
The only solution is to substitute print $scripts with print $drupal_get_js() in the head section.
By the time page.tpl.php is called, the $scripts variable has already been defined, so using drupal_add_js won't work at that level. You can either fix it the way you've already done, or redefine the $scripts variable in your template.php file. Something along the lines of:
in _phptemplate_variables() function: drupal_add_js(...new js...); $vars['scripts'] = drupal_get_js();
or top level, outside of any functions: drupal_add_js(...new js...);
This second method works since the template.php script is included before the $scripts variable is defined...
Cheers, Jonathan