You are here

function my_module_render_slick_theme in Slick Carousel 7.2

Using slick_attach() to a custom theme or renderable array.

The slick_attach() is just an array as normally used with #attached property. This can be used to merge extra 3d party libraries along with the slick. Previously slick_add() was provided as a fallback. It was dropped since it was never actually used by slick. However you can add slick assets using a few alternatives: drupal_add_library(), drupal_add_js(), or the recommended #attached, the D8 way, just as easily. Hence slick_attach() acts as a shortcut to load the basic Slick assets.

Passing an empty array will load 3 basic files:

  • slick.min.js, slick.css, slick.load.min.js.

File

./slick.api.php, line 394
Hooks and API provided by the Slick module.

Code

function my_module_render_slick_theme() {

  // Empty array for the basic files, or optionally pass a skin to have a proper
  // display where appropriate, see slick_fields/slick_views for more samples.
  $attach = array();
  $settings = array(
    'skin' => 'fullwidth',
    'skin_thumbnail' => 'asnavfor',
  );
  $attachments = slick_attach($attach, $settings);

  // Add another custom library to the array.
  $transit = libraries_get_path('jquery.transit') . '/jquery.transit.min.js';
  $attachments['js'] += array(
    $transit => array(
      'group' => JS_LIBRARY,
      'weight' => -5,
    ),
  );

  // Add another asset.
  $my_module_path = drupal_get_path('module', 'my_module');
  $attachments['css'] += array(
    $my_module_path . '/css/my_module.css' => array(
      'weight' => 5,
    ),
  );

  // Pass the $attachments to theme_slick(), or any theme with bigger scope.
  $my_module_theme = array(
    '#theme' => 'my_module_theme',
    // More properties...
    '#attached' => $attachments,
  );
  return $my_module_theme;
}