Enterprise Drupal 8 Development by Todd Tomlinson
Author:Todd Tomlinson
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA
annoying-cow:
version: 1.x
js:
js/annoying-cow.js: {}
Finally, we update the libraries section of the davinci.info.yml file to load the annoying-cow library .
libraries:
- davinci/global-styling
- davinci/annoying-cow
After saving all the files and rebuilding cache, reload the homepage. The annoying cow is shown in Figure 5-9.
Figure 5-9.Demonstrating that the added JavaScript works
Adding JavaScript and CSS Libraries to Template Files
In the previous examples, we added CSS and JavaScript to the Davinci module on a global basis, meaning that every page will load the CSS and the JavaScript that we added through the libraries section of the davinci.info.yml file. This approach works but isn’t the optimal solution, as not all CSS or JavaScript is required on every page.
To resolve the issue, Twig provides the ability to load libraries on a per-template basis through the attach_library function in the form of {{ attach_library('library_name') }}. In the case of the Davinci theme, we could add the node.css file, which is loaded only when the node.html.twig template is used to render a node. We first need to add a new library to the davinci.libraries.yml file to define the library:
node-styling:
version: 1.x
css:
theme:
css/theme/node.css: {}
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8310)
Test-Driven Development with Java by Alan Mellor(6832)
Data Augmentation with Python by Duc Haba(6752)
Principles of Data Fabric by Sonia Mezzetta(6492)
Learn Blender Simulations the Right Way by Stephen Pearson(6398)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6264)
Hadoop in Practice by Alex Holmes(5966)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5816)
RPA Solution Architect's Handbook by Sachin Sahgal(5666)
Big Data Analysis with Python by Ivan Marin(5412)
The Infinite Retina by Robert Scoble Irena Cronin(5358)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5164)
Pretrain Vision and Large Language Models in Python by Emily Webber(4383)
Infrastructure as Code for Beginners by Russ McKendrick(4149)
Functional Programming in JavaScript by Mantyla Dan(4044)
The Age of Surveillance Capitalism by Shoshana Zuboff(3964)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3863)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3663)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3641)
