By HelpDrupalHelpMe on
I am trying to enable a custom javascript menu on my drupal. I have come across this link which I believe tells you how to enable your own custom Javascript files in drupal. http://api.drupal.org/api/function/drupal_add_js/5
But I don't get where the PHP and Javascript.js files go, how do I call the function.
I've tried putting the snippet below in my page-front.tpl.php and template.php but my site totally crashes. I put the .JS files in my 'misc/' folder.
The thing that always confuses me the most is where this stuff is suppose to go, I wish people writing the tutorial would make that clear.
So where should I place the PHP snippet and the .js files so that my menu will work. FOR EXAMPLE,
<?php
function drupal_add_js($data = NULL, $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE) {
if (!is_null($data)) {
_drupal_add_js('misc/jquery.js', 'core', 'header', FALSE, $cache);
_drupal_add_js('misc/drupal.js', 'core', 'header', FALSE, $cache);
}
return _drupal_add_js($data, $type, $scope, $defer, $cache);
}
?>
Comments
Everything goes in
Everything goes in sites/all/themes > for this sort of thing.
===========
read my thoughts
Of course ....
Of course it crashed. You're supposed to call the function, not attempt to redefine it.
In your template.php:
drupal_add_js('path/to/yourscript.js', 'theme');
This tells Drupal to add your javascript to the stack that will be output in the page header when it's generated.
Wow those were the fastest
Wow those were the fastest responses I've received to date on Drupal! Next stop: Learning php.
When I add that line I get
When I add that line I get the white screen of death. What could I be doing wrong?