1

I would like to attach a CSS file and a JS library on Slick Views module from a custom module. Is there a hook function for Slick Views or any solution?

5
  • 2
    Possible duplicate of How do I add JavaScript specific for a view?
    – leymannx
    Commented Apr 16, 2019 at 20:40
  • @leymannx The link you provide is the hook function for template.php views. I need to load a JS library when a Slick Views render on a page.
    – CocoSkin
    Commented Apr 16, 2019 at 20:48
  • 1
    Which is exactly what this duplicate question answers already. You can place the code in a module as well. If view == my_slick_view, then fire drupal_add_js/css.
    – leymannx
    Commented Apr 16, 2019 at 20:50
  • @leymannx This function target a specific view name. I have a multisite that contains 100+ sites. It will be an issue if anyone create a new slick views with different views name.
    – CocoSkin
    Commented Apr 17, 2019 at 12:55
  • Then check for other attributes then the name. Depends on you.
    – leymannx
    Commented Apr 17, 2019 at 12:58

1 Answer 1

0

Picking up from @leymannx (and copy/pasting from the linked answer) here's a more spelled-out solution:

You could use the template_preprocess_views_view() hook to do this:

function THEME_preprocess_views_view(&$vars) {
  $view = &$vars['view'];
  // Make sure it's the correct view
  if ($view->name == 'my_slick_view') {
    // add needed javascript
    drupal_add_js(drupal_get_path('theme', 'your-theme') . '/your-js.js');
    // add needed stylesheet
    drupal_add_css(drupal_get_path('theme', 'your-theme') . '/your-css.css');
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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