- First commit to issue fork.
- @harish1688 opened merge request.
- 🇮🇳India Harish1688 India
Hi @drupalfan2 →
step 1 - In your sub-theme folder in custom_theme.libraries.yml file paste below code, this create a link of main.js: in scripts folder JS file .#global custom global: version: 8.x-3.1 js: scripts/main.js: {}
step 2 - In your sub-theme folder in custom_theme.info.yml file paste below code, that will connect global libraries with your theme.
# custom library libraries: - custom_theme/global
step 3 - In your sub-theme folder in scripts folder create a file with name main.js.
you may testing by pasting the code./** * @file main.js */ // Attach all behaviors. (function($, Drupal, once, drupalSettings) { "use strict"; Drupal.behaviors.global = { attach: function(context, settings) { // Attach first behaviors - you may bind the behavior on any element like 'html/body' once('myCustomBehavior', 'html', context).forEach(function(element) { console.log('first behavior ready'); }); // Attach second behaviors - you may bind the behavior on any element like 'html/body' once('myCustomBehavior_2', 'body', context).forEach(function(element) { console.log('second behavior ready'); }); } }; })(jQuery, Drupal, once, drupalSettings);
Note :
change custom_theme name with sub-theme name.