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?
-
2Possible duplicate of How do I add JavaScript specific for a view?– leymannxCommented 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.– CocoSkinCommented Apr 16, 2019 at 20:48
-
1Which 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.– leymannxCommented 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.– CocoSkinCommented Apr 17, 2019 at 12:55
-
Then check for other attributes then the name. Depends on you.– leymannxCommented Apr 17, 2019 at 12:58
Add a comment
|
1 Answer
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');
}
}