Skip to content

Instantly share code, notes, and snippets.

@brunodbo
Forked from steffenr/mymodule.libraries.yml
Created May 12, 2017 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunodbo/ff8f4727a2b7ed4c1cfdf91156f0c098 to your computer and use it in GitHub Desktop.
Save brunodbo/ff8f4727a2b7ed4c1cfdf91156f0c098 to your computer and use it in GitHub Desktop.
Attach a CSS or JS library to a View in Drupal 8
custom_view:
css:
component:
css/custom_view.css: {}
<?php
/**
* Implements hook_views_pre_render().
*/
function custom_views_pre_render(ViewExecutable $view) {
if (isset($view) && ($view->storage->id() == 'my_view')) {
$view->element['#attached']['library'][] = 'custom/custom_view';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment