Custom module javascript Drupal.behaviours doesn't seems to loadjquery is not adding a classNot able to reference Javascript functions inside jQuery wrapperHow do I add a Javascript library to a field formatter?Module library dependancies is not workingJavascript will not load for anonymous usersAttach javascript library and settings to a node pagehello_world_page_attachments is not calledhow can I pass array from drupal code to js fileHow to add variables in *.libraries.yml in drupal 8What's the correct way to pass variables to the JavaScript of a custom CKEditor plugin?

What should the arbiter and what should have I done in this case?

"You've got another thing coming" - translation into French

Why was the Sega Genesis marketed as a 16-bit console?

What risks are there when you clear your cookies instead of logging off?

How to retract an idea already pitched to an employer?

Russian equivalents of "no love lost"

Why only the fundamental frequency component is said to give useful power?

Is open-sourcing the code of a webapp not recommended?

When conversion from Integer to Single may lose precision

Should I compare a std::string to "string" or "string"s?

How do governments keep track of their issued currency?

How to chain Python function calls so the behaviour is as follows

What can I, as a user, do about offensive reviews in App Store?

Chemmacros scheme translation

How to generate all commutative pairings of list elements?

Using "subway" as name for London Underground?

Is the term 'open source' a trademark?

Can a user sell my software (MIT license) without modification?

How does an ordinary object become radioactive?

How to project 3d image in the planes xy, xz, yz?

Should an arbiter claim draw at a K+R vs K+R endgame?

Where does "0 packages can be updated." come from?

Compiling c files on ubuntu and using the executable on Windows

Implement Homestuck's Catenative Doomsday Dice Cascader



Custom module javascript Drupal.behaviours doesn't seems to load


jquery is not adding a classNot able to reference Javascript functions inside jQuery wrapperHow do I add a Javascript library to a field formatter?Module library dependancies is not workingJavascript will not load for anonymous usersAttach javascript library and settings to a node pagehello_world_page_attachments is not calledhow can I pass array from drupal code to js fileHow to add variables in *.libraries.yml in drupal 8What's the correct way to pass variables to the JavaScript of a custom CKEditor plugin?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have a custom module which has a javascript file. Here's the content of the javascript file:



(function ($, Drupal) 
Drupal.behaviors.promotionalOverlayBlock =
attach: function(context, settings)
console.log("hello world")

;
)(jQuery, Drupal);


The location of javascript file:



mymodule/js/overlayblock.js


In my mymodule.libraries.yml file it has the following:



mymodule:
js:
js/overlayblock.js:
dependencies:
- core/jquery
- core/jquery.once
- core/drupalSettings


When I load my drupal page, I expecting to see the "hello world" in the browser console. However, nothing show up. I view the page html code and search for my javascript there, but I can't seems to find anything related to my javascript file.



What could be the problem here?



Here's how I attached my library through the hook_preprocess_block() I'm not sure if this is the right place to add the attached.



function mymodule_preprocess_block(&variables)
$variables['#attached']['library'][] =
'mymodule/overlayblock';










share|improve this question



















  • 1





    While you created all the files, you still need to load/call/attach the library somewhere. That somewhere depends on where you want this to load at. Every page? a specific page? every form? specific form? etc...

    – No Sssweat
    May 29 at 5:23












  • That's correct @NoSssweat It's suppose to load on a page where I assigned my block to it. I can see the block on that page, but the javascript file doesn't seems to load. I'm wondering if there's anything to configure apart from the above.

    – fkaufusi
    May 29 at 5:38







  • 1





    @fkaufusi did you attach library mymodule/mymodule to that block? Can you show your code how you did that? If you don't, what type of block do you use, Plugin Block or Entity Block? The approaches for them will be different.

    – Niklan
    May 29 at 6:03











  • @Niklan thanks for mentioning that "attach" I just added that attached now. Edited the question to add more info. Do you think the hook_preprocess_block() is the correct place to add the "attach"?

    – fkaufusi
    May 29 at 6:46











  • First of all. What "block" do you use? It's Plugin Block or you created it via admin interface? Those block types are different and have different approaches to attach library, your example is for block template (affects all block on the site, which is not good). Second, you attach the library mymodule/overlayblock. The library naming is [module_name]/[library_name]. In your mymodule.libraries.yml you named library as mymodule, so you must attach mymodule/mymodule library.

    – Niklan
    May 29 at 7:10

















1















I have a custom module which has a javascript file. Here's the content of the javascript file:



(function ($, Drupal) 
Drupal.behaviors.promotionalOverlayBlock =
attach: function(context, settings)
console.log("hello world")

;
)(jQuery, Drupal);


The location of javascript file:



mymodule/js/overlayblock.js


In my mymodule.libraries.yml file it has the following:



mymodule:
js:
js/overlayblock.js:
dependencies:
- core/jquery
- core/jquery.once
- core/drupalSettings


When I load my drupal page, I expecting to see the "hello world" in the browser console. However, nothing show up. I view the page html code and search for my javascript there, but I can't seems to find anything related to my javascript file.



What could be the problem here?



Here's how I attached my library through the hook_preprocess_block() I'm not sure if this is the right place to add the attached.



function mymodule_preprocess_block(&variables)
$variables['#attached']['library'][] =
'mymodule/overlayblock';










share|improve this question



















  • 1





    While you created all the files, you still need to load/call/attach the library somewhere. That somewhere depends on where you want this to load at. Every page? a specific page? every form? specific form? etc...

    – No Sssweat
    May 29 at 5:23












  • That's correct @NoSssweat It's suppose to load on a page where I assigned my block to it. I can see the block on that page, but the javascript file doesn't seems to load. I'm wondering if there's anything to configure apart from the above.

    – fkaufusi
    May 29 at 5:38







  • 1





    @fkaufusi did you attach library mymodule/mymodule to that block? Can you show your code how you did that? If you don't, what type of block do you use, Plugin Block or Entity Block? The approaches for them will be different.

    – Niklan
    May 29 at 6:03











  • @Niklan thanks for mentioning that "attach" I just added that attached now. Edited the question to add more info. Do you think the hook_preprocess_block() is the correct place to add the "attach"?

    – fkaufusi
    May 29 at 6:46











  • First of all. What "block" do you use? It's Plugin Block or you created it via admin interface? Those block types are different and have different approaches to attach library, your example is for block template (affects all block on the site, which is not good). Second, you attach the library mymodule/overlayblock. The library naming is [module_name]/[library_name]. In your mymodule.libraries.yml you named library as mymodule, so you must attach mymodule/mymodule library.

    – Niklan
    May 29 at 7:10













1












1








1


1






I have a custom module which has a javascript file. Here's the content of the javascript file:



(function ($, Drupal) 
Drupal.behaviors.promotionalOverlayBlock =
attach: function(context, settings)
console.log("hello world")

;
)(jQuery, Drupal);


The location of javascript file:



mymodule/js/overlayblock.js


In my mymodule.libraries.yml file it has the following:



mymodule:
js:
js/overlayblock.js:
dependencies:
- core/jquery
- core/jquery.once
- core/drupalSettings


When I load my drupal page, I expecting to see the "hello world" in the browser console. However, nothing show up. I view the page html code and search for my javascript there, but I can't seems to find anything related to my javascript file.



What could be the problem here?



Here's how I attached my library through the hook_preprocess_block() I'm not sure if this is the right place to add the attached.



function mymodule_preprocess_block(&variables)
$variables['#attached']['library'][] =
'mymodule/overlayblock';










share|improve this question
















I have a custom module which has a javascript file. Here's the content of the javascript file:



(function ($, Drupal) 
Drupal.behaviors.promotionalOverlayBlock =
attach: function(context, settings)
console.log("hello world")

;
)(jQuery, Drupal);


The location of javascript file:



mymodule/js/overlayblock.js


In my mymodule.libraries.yml file it has the following:



mymodule:
js:
js/overlayblock.js:
dependencies:
- core/jquery
- core/jquery.once
- core/drupalSettings


When I load my drupal page, I expecting to see the "hello world" in the browser console. However, nothing show up. I view the page html code and search for my javascript there, but I can't seems to find anything related to my javascript file.



What could be the problem here?



Here's how I attached my library through the hook_preprocess_block() I'm not sure if this is the right place to add the attached.



function mymodule_preprocess_block(&variables)
$variables['#attached']['library'][] =
'mymodule/overlayblock';







8 theming javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 29 at 7:08







fkaufusi

















asked May 29 at 5:15









fkaufusifkaufusi

19411




19411







  • 1





    While you created all the files, you still need to load/call/attach the library somewhere. That somewhere depends on where you want this to load at. Every page? a specific page? every form? specific form? etc...

    – No Sssweat
    May 29 at 5:23












  • That's correct @NoSssweat It's suppose to load on a page where I assigned my block to it. I can see the block on that page, but the javascript file doesn't seems to load. I'm wondering if there's anything to configure apart from the above.

    – fkaufusi
    May 29 at 5:38







  • 1





    @fkaufusi did you attach library mymodule/mymodule to that block? Can you show your code how you did that? If you don't, what type of block do you use, Plugin Block or Entity Block? The approaches for them will be different.

    – Niklan
    May 29 at 6:03











  • @Niklan thanks for mentioning that "attach" I just added that attached now. Edited the question to add more info. Do you think the hook_preprocess_block() is the correct place to add the "attach"?

    – fkaufusi
    May 29 at 6:46











  • First of all. What "block" do you use? It's Plugin Block or you created it via admin interface? Those block types are different and have different approaches to attach library, your example is for block template (affects all block on the site, which is not good). Second, you attach the library mymodule/overlayblock. The library naming is [module_name]/[library_name]. In your mymodule.libraries.yml you named library as mymodule, so you must attach mymodule/mymodule library.

    – Niklan
    May 29 at 7:10












  • 1





    While you created all the files, you still need to load/call/attach the library somewhere. That somewhere depends on where you want this to load at. Every page? a specific page? every form? specific form? etc...

    – No Sssweat
    May 29 at 5:23












  • That's correct @NoSssweat It's suppose to load on a page where I assigned my block to it. I can see the block on that page, but the javascript file doesn't seems to load. I'm wondering if there's anything to configure apart from the above.

    – fkaufusi
    May 29 at 5:38







  • 1





    @fkaufusi did you attach library mymodule/mymodule to that block? Can you show your code how you did that? If you don't, what type of block do you use, Plugin Block or Entity Block? The approaches for them will be different.

    – Niklan
    May 29 at 6:03











  • @Niklan thanks for mentioning that "attach" I just added that attached now. Edited the question to add more info. Do you think the hook_preprocess_block() is the correct place to add the "attach"?

    – fkaufusi
    May 29 at 6:46











  • First of all. What "block" do you use? It's Plugin Block or you created it via admin interface? Those block types are different and have different approaches to attach library, your example is for block template (affects all block on the site, which is not good). Second, you attach the library mymodule/overlayblock. The library naming is [module_name]/[library_name]. In your mymodule.libraries.yml you named library as mymodule, so you must attach mymodule/mymodule library.

    – Niklan
    May 29 at 7:10







1




1





While you created all the files, you still need to load/call/attach the library somewhere. That somewhere depends on where you want this to load at. Every page? a specific page? every form? specific form? etc...

– No Sssweat
May 29 at 5:23






While you created all the files, you still need to load/call/attach the library somewhere. That somewhere depends on where you want this to load at. Every page? a specific page? every form? specific form? etc...

– No Sssweat
May 29 at 5:23














That's correct @NoSssweat It's suppose to load on a page where I assigned my block to it. I can see the block on that page, but the javascript file doesn't seems to load. I'm wondering if there's anything to configure apart from the above.

– fkaufusi
May 29 at 5:38






That's correct @NoSssweat It's suppose to load on a page where I assigned my block to it. I can see the block on that page, but the javascript file doesn't seems to load. I'm wondering if there's anything to configure apart from the above.

– fkaufusi
May 29 at 5:38





1




1





@fkaufusi did you attach library mymodule/mymodule to that block? Can you show your code how you did that? If you don't, what type of block do you use, Plugin Block or Entity Block? The approaches for them will be different.

– Niklan
May 29 at 6:03





@fkaufusi did you attach library mymodule/mymodule to that block? Can you show your code how you did that? If you don't, what type of block do you use, Plugin Block or Entity Block? The approaches for them will be different.

– Niklan
May 29 at 6:03













@Niklan thanks for mentioning that "attach" I just added that attached now. Edited the question to add more info. Do you think the hook_preprocess_block() is the correct place to add the "attach"?

– fkaufusi
May 29 at 6:46





@Niklan thanks for mentioning that "attach" I just added that attached now. Edited the question to add more info. Do you think the hook_preprocess_block() is the correct place to add the "attach"?

– fkaufusi
May 29 at 6:46













First of all. What "block" do you use? It's Plugin Block or you created it via admin interface? Those block types are different and have different approaches to attach library, your example is for block template (affects all block on the site, which is not good). Second, you attach the library mymodule/overlayblock. The library naming is [module_name]/[library_name]. In your mymodule.libraries.yml you named library as mymodule, so you must attach mymodule/mymodule library.

– Niklan
May 29 at 7:10





First of all. What "block" do you use? It's Plugin Block or you created it via admin interface? Those block types are different and have different approaches to attach library, your example is for block template (affects all block on the site, which is not good). Second, you attach the library mymodule/overlayblock. The library naming is [module_name]/[library_name]. In your mymodule.libraries.yml you named library as mymodule, so you must attach mymodule/mymodule library.

– Niklan
May 29 at 7:10










2 Answers
2






active

oldest

votes


















3














When attached make sure to use the correct name of the "library"



Inside your mymodule.libraries.yml file. The first line is your library name.



I use a different name inside my library file, and I attached a wrong library name.



 function mymodule_preprocess_block(&variables)
$variables['#attached']['library'][] =
'mymodule/mylibraryname';



My library file mymodule.libraries.yml



mylibraryname:
js:
js/promotional-overlay-block.js:
dependencies:
- core/jquery
- core/jquery.once
- core/drupalSettings





share|improve this answer






























    2














    In Case if your library called mymodule, then attached shoud be as i described below



    function mytheme_preprocess_block(&$variables) 
    if ($variables['elements']['#id'] == 'myblock')
    $variables['#attached']['library'][] = 'module_name/mymodule';







    share|improve this answer























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "220"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f281712%2fcustom-module-javascript-drupal-behaviours-doesnt-seems-to-load%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      When attached make sure to use the correct name of the "library"



      Inside your mymodule.libraries.yml file. The first line is your library name.



      I use a different name inside my library file, and I attached a wrong library name.



       function mymodule_preprocess_block(&variables)
      $variables['#attached']['library'][] =
      'mymodule/mylibraryname';



      My library file mymodule.libraries.yml



      mylibraryname:
      js:
      js/promotional-overlay-block.js:
      dependencies:
      - core/jquery
      - core/jquery.once
      - core/drupalSettings





      share|improve this answer



























        3














        When attached make sure to use the correct name of the "library"



        Inside your mymodule.libraries.yml file. The first line is your library name.



        I use a different name inside my library file, and I attached a wrong library name.



         function mymodule_preprocess_block(&variables)
        $variables['#attached']['library'][] =
        'mymodule/mylibraryname';



        My library file mymodule.libraries.yml



        mylibraryname:
        js:
        js/promotional-overlay-block.js:
        dependencies:
        - core/jquery
        - core/jquery.once
        - core/drupalSettings





        share|improve this answer

























          3












          3








          3







          When attached make sure to use the correct name of the "library"



          Inside your mymodule.libraries.yml file. The first line is your library name.



          I use a different name inside my library file, and I attached a wrong library name.



           function mymodule_preprocess_block(&variables)
          $variables['#attached']['library'][] =
          'mymodule/mylibraryname';



          My library file mymodule.libraries.yml



          mylibraryname:
          js:
          js/promotional-overlay-block.js:
          dependencies:
          - core/jquery
          - core/jquery.once
          - core/drupalSettings





          share|improve this answer













          When attached make sure to use the correct name of the "library"



          Inside your mymodule.libraries.yml file. The first line is your library name.



          I use a different name inside my library file, and I attached a wrong library name.



           function mymodule_preprocess_block(&variables)
          $variables['#attached']['library'][] =
          'mymodule/mylibraryname';



          My library file mymodule.libraries.yml



          mylibraryname:
          js:
          js/promotional-overlay-block.js:
          dependencies:
          - core/jquery
          - core/jquery.once
          - core/drupalSettings






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 29 at 7:25









          fkaufusifkaufusi

          19411




          19411























              2














              In Case if your library called mymodule, then attached shoud be as i described below



              function mytheme_preprocess_block(&$variables) 
              if ($variables['elements']['#id'] == 'myblock')
              $variables['#attached']['library'][] = 'module_name/mymodule';







              share|improve this answer



























                2














                In Case if your library called mymodule, then attached shoud be as i described below



                function mytheme_preprocess_block(&$variables) 
                if ($variables['elements']['#id'] == 'myblock')
                $variables['#attached']['library'][] = 'module_name/mymodule';







                share|improve this answer

























                  2












                  2








                  2







                  In Case if your library called mymodule, then attached shoud be as i described below



                  function mytheme_preprocess_block(&$variables) 
                  if ($variables['elements']['#id'] == 'myblock')
                  $variables['#attached']['library'][] = 'module_name/mymodule';







                  share|improve this answer













                  In Case if your library called mymodule, then attached shoud be as i described below



                  function mytheme_preprocess_block(&$variables) 
                  if ($variables['elements']['#id'] == 'myblock')
                  $variables['#attached']['library'][] = 'module_name/mymodule';








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 29 at 6:49









                  Igor TaldenkoIgor Taldenko

                  211




                  211



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Drupal Answers!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f281712%2fcustom-module-javascript-drupal-behaviours-doesnt-seems-to-load%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                      Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                      Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form