Skip to content

Instantly share code, notes, and snippets.

@thamas
Created October 12, 2018 12:27
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 thamas/0af271c32f9eb2c1f05631f313e112a1 to your computer and use it in GitHub Desktop.
Save thamas/0af271c32f9eb2c1f05631f313e112a1 to your computer and use it in GitHub Desktop.

philw_ [Today at 5:08 PM] I’m trying to use a Drupal behaviour in Emulsify, I’ve got Emulsify correctly loading domready and drupal.js in my _01-foot.twig file, but my behaviour file is erroring with a ‘Uncaught ReferenceError: Drupal is not defined’ error, presumably because the component’s JS is being output before the script tag for drupal.js is output in the footer. Has anyone worked around this before? (edited)

16 replies jsheffers [21 hours ago] I’m doing the same thing and I don’t have any issues, and I have components using Drupal behaviors (edited)

philw_ [21 hours ago] Interesting! Do you add your {{attach_library('theme/whatever') }} calls in your component Twig files? When I do that it doesn’t work, but if I add them to my footer file (below drupal.js) then it does work

jsheffers [21 hours ago] Oh I know why it works for me

philw_ [21 hours ago] https://github.com/fourkitchens/emulsify/wiki/Drupal-Usage#javascript-in-drupal encourages users to use attach_library from their component Twig files, but that doesn’t seem to work for me because the order is wrong, the component library is added before Drupal.js has created the window.Drupal object, so the behaviours aren’t created (edited)

jsheffers [21 hours ago] Because I’m looping through all of the JS in the components folder and concatenating it, then manually loading it in the footer

jsheffers [21 hours ago] via gulp

philw_ [21 hours ago] Ahhh 🙂

jsheffers [21 hours ago] So all of the JS from the components lives in a JS file that only pattern-lab digests

jsheffers [21 hours ago] and then in the drupal templates I attach the library

evanmwillhite [21 hours ago] @philw_ this is a big known issue and it's where I plan on spending my time as soon as I can. Here's an issue in case it helps fourkitchens/emulsify#287 GitHub Getting Drupal.behaviors to work in PL · Issue #287 · fourkitchens/emulsify What are the steps to getting Drupal.behaviors to work in Pattern Lab? Has it changed since the addition of the new pl_attach-library function? I had them working in an older emulsify-based project...

philw_ [21 hours ago] Ah great @evanmwillhite 🙂

evanmwillhite [21 hours ago] "great" 😂

philw_ [21 hours ago] Hahah sorry, I just meant that it’s great that you proactively have a ticket for it 😄

philw_ [21 hours ago] Your workaround in the comment thread is basically what I stumbled upon, but I’ll leave a comment if I find anything else useful

philw_ [21 hours ago] We have the added complication on my project that symlinks break our Bamboo build jobs, so I’m having to copy files across manually at the moment 😞 I’ll script it eventually, but right now manually will have to do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment