Friday, November 9, 2018

Adding JS libraries to a Drupal project with Libraries API

Step 1: 

Add all external libraries into "sites/all/libraries"

For example:

jquery.themepunch.revolution.min.js
extensions/revolution.extension.actions.min.js

and

css/settings.css

Step 2:


Register the external libraries within your module
  
function MYMODULENAME_libraries_info() {

  $libraries = array();

$libraries['revolution'] = array(
    'name' => 'Revolution Slider',
    'vendor url' => 'https://revolution.themepunch.com/',
    'download url' => 'https://revolution.themepunch.com/',
    'version' => '5.4.8',
    'files' => array(
      'js' => array(
        'jquery.themepunch.revolution.min.js',
        'extensions/revolution.extension.actions.min.js',
      ),
      'css' => array(
        'css/settings.css',
      ),
    ),
  );
}

Step 3:



Create a new function within the .module file to call the new library
function loadRevSlider() {
  libraries_load('revolution');
}

Step 4:


Use the newly created function anywhere u want to use them
loadRevSlider();

No comments:

Post a Comment