How do you add jQuery tabs in a "template.php" file?
I'm trying to add it with drupal_add_library('system', 'jQuery.tabs') or drupal_add_js('/misc/ui/jquery.ui.tabs.min.js'), but I'm not having any luck.

Here's my full snippet:

function custom_theme(&$existing, $type, $theme, $path) {
  $hooks = array(); 
  drupal_add_library('system', 'ui.tabs');
  // custom.js will call jQuery.tabs!
  drupal_add_js( path_to_theme() .'/js/custom.js', array('weight' => 9));

  return $hooks;
}
share|improve this question
Remember to accept answers for your questions; doing so, your reputation will be increased, and you will help this site to go past the beta phase. – kiamlaluno Apr 30 '11 at 12:55

1 Answer

up vote 2 down vote accepted

hook_theme() is a hook that must returns the list of theme functions implemented by a module, or a theme.

Calling drupal_add_library() or drupal_add_js() inside hook_theme() is not the way to add a JavaScript file to a page.

As reported in Structure of the .info file, a theme can use the scripts directive to declare the JavaScript files that it uses.

scripts[] = js/custom.js

Alternatively, a theme can use drupal_add_js() inside a theme function, or use the following snipped inside page.tpl.php, or any alternative page template Drupal would use.

drupal_add_js($path_to_script);
$scripts = drupal_get_js();
share|improve this answer
What if i wanted to load it on only a particular page. I.e. I only have tabs on a particular node – chrisjlee Apr 12 '11 at 14:35
@Chris J. Lee I will expand my answer. – kiamlaluno Apr 12 '11 at 14:48

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.