1

What is best way to integrate external jQuery plugin? can i use it without libraries module?

5

Perhaps the simplest way is to add it to your theme.info file

e.g, in mytheme.info

scripts[] = js/jquery.cycle.min.js

That will add it globally sitewide.

For more selective control, use drupal_add_js

e.g, in template.php

/**
 * Implements hook_preprocess_html
 */
function mytheme_preprocess_html($variables){

  $valid_path = ''; // TODO, check arg(), current_path() etc.. for valid_path
  if ($valid_path){
    drupal_add_js(drupal_get_path('theme', 'mytheme'). '/js/jquery.cycle.min.js');
  }

}

An advanced method is to use the Libraries API and hook_libraries_info however any of these methods will work.

1

A jQuery plugin does not make any difference to any other JavaScript file.

The best way is to use the Drupal module, if there is one available. If the jQuery plugin is popular, there is a chance that there is already one module that incorporates it. That way you don't have to care about testing or upgrades, others do.

If there is no module available in Drupal.org, you can create it yourself. Using the Libraries API is not required but encouraged, so that other future modules can make the best use of it as well.

Use the drupal_add_js function in your module or theme to include a JavaScript file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy