2

In Drupal 8 the weight for javascript files in libraries is not supported, or at least only negative values are allowed, which means I am only able to position them at the top of the list (i.e. load it first) but not at the end of the list.

I have a library for the Zurb Foundation and its initialization has to be loaded last. It is a requirement for my theme and I don't want to override a template to fix this problem.

How is one supposed to do this?

  • What is the code you are currently using to add the library? – rooby Apr 20 '15 at 1:19
  • rooby: it's just a library dependency in theme's base library file. – user21641 Apr 20 '15 at 6:11
1

I was surprised hear that "only negative values are allowed" as JS weights, so I had to hunt that down. And it's true... https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Asset%21LibraryDiscoveryParser.php/function/LibraryDiscoveryParser%3A%3AbuildByExtension/8.2.x There is an exception error message that says, "The $extension/$id library defines a positive weight for '$source'. Only negative weights are allowed (but should be avoided). Instead of a positive weight, specify accurate dependencies for this library."

This of course reminded me that, yes indeed, dependencies were added/improved in Drupal 8 so that we didn't have to worry about this. Oddly enough, there are several core JS files that define weight, so I guess we are only part way there.

So, this is just a long-winded way of saying, what scripts does the Zurb Foudation depend on? And can you list those dependencies in your libraries file under the Zurb script? See https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module for more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy