Loading of assets via Libraries API
I'm writing a new module which has a dependency on an external library. In Drupal 7 I would use hook_libraries_info giving the name of the library the required assets and Drupal would search the valid locations, libraries directories, to load these assets when required. Drupal 8 introduces *.libraries.yml and after reading https://www.drupal.org/no...
Get path to theme assets in Twig template
I have a question about getting a path to an image in a Twig template. The image is not assigned to a field or something. Just a static image which is stored in "MYTHEME/image/icon/my-icon.png". In Drupal 7 I get the path in my node.template with the following code: How does it work with in Drupal 8? I tried to pass a variable in template_preproces...
How do I include JavaScript with assets (libraries.yml)?
This is my mytheme.libraries.yml file: This is my js/effect.js file: I created jquery.js in core folder of my site root. Even if I remove the dependency line from my libraries.yml and remove jquery syntax from my effect.js, I receive nothing on my site.
How to modify .htaccess to serve brotli compressed static assets over gziped ones?
I'm trying to use brotli compressed static assets with Advanced CSS/JS Aggregation as detailed here, https://www.drupal.org/node/2773807. The assets are created as they should be, but they're never served because the .htaccess file doesn't know to do that. lyncd.com has a short walkthrough, https://lyncd.com/2015/11/brotli-support-apache/, but I ha...
Attaching assets if the page contains a table
I want to attach a CSS file to a page only if it contains a table. I tried from the guide "Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 module" but it does not work. The hook itself and the condition works. The question is where I have to save the #attached array in the $types variable? I appreciate your help and feedback. PS: The fol...