How do I include JavaScript with assets (libraries.yml)?

Solutions

Most times it's about blanks. The yml files are very picky about this. Looks like your effects.js has 6 blanks instead of four.

And make sure, that you have your global-styling listed in the libraries section of your theme.info.yml.

Similar questions

How can I add 'text/jsx' type to a script tag via libraries.yml?
I want to add some react js files to a theme's libraries.yml and I don't know how I can do this in drupal 8. <script type="text/babel" src="scripts/example.js"></script> or <script type="text/jsx" src="scripts/example.js"></script> I can't figure it out hot to make the type="text/jsx" appear when the file is added to the pag...
CSS order in Drupal 8 libraries.yml
From what I read about Drupal 8 themes there does not appear to be anything to order CSS file loading. As you know, CSS cascades down to a specific order when there is a conflict with an element. Since I have a class that is named the same as Twitter Bootstrap which is loaded from the CDN from the page.html.twig, I can usually modify a bootstrap cl...
Is there a way to override paths defined in *.libraries.yml
Guess I found a bug here and already filed it: libraries_get_path('mmenu') returns correct path (profiles/profile_name/libraries/mmenu). drupal_get_profile() returns correct profile. Drupal seems to only take the paths defined in mmenu.libraries.yml into account. Changing them makes everything work as desired. So, I'm asking myself now: Is there an...
8: How to specify multiple css media types in a libraries.yml file
Entering the list "screen, print" doesn't work: The resulting HTML should be:
How to add variables in *.libraries.yml in drupal 8
I need to convert the below code added in hook_page_attachments() and add the external js in *.libraries.yml but not sure how to add variables like $token and $user->mail in the *.libraries.yml so I can just attach library Add Your Script to a file In *.libraries.yml, I have added Added that file to the library under $attachments['#attached']['libr...
How do I get link the files in libraries.yml with absolute url path
In my libraries.yml files the css files are linked with the relative url paths. Eg : /css/mycss.html So when in the page source the linked url shows as relative. How do I link those files with absolute URL path?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.