This extension adds 2 useful JavaScript snippets that can be used with Drupal 8. These snippets were extracted from the JavaScript API overview documentation.
To install this extension use the following steps:
- In VS Code, open the Command Palette using the shortcut key combination
ctrl-shift-p
(Windows, Linux) orcmd-shift-p
(OSX) - Then in the Command Palette box, type in
Install Extensions
and select that form the list. - This will open up the Extension Manager. In the search box type in
Drupal 8 JavaScript Snippets
. - Click the Install button, after that finishes make sure to reload VS Code as well.
Once installed, to use these snippets you can use the following two methods, the first Method is geared towards people who are new to the snippets available while the second method is suitable for people who know the available snippets and are looking to increase their speed.
- Open the Command Palette,
ctrl-shift-p
(Windows, Linux) orcmd-shift-p
(OSX) - In the command box type in
Insert Snippet
; this will list all the available snippets. - Select the snippet you want to use from the provided list.
- In the code editor window, type in the Prefix of the snippet you want to insert. This will show an intellisense window as you type.
- Insert the snippet you want by simply pressing the
tab
key.
Here you will find all the code snippets that are available in this extension. Please note that each title starts with the Prefix of the code snippet to insert; useful to memorize them if you plan to use Method 2 above.
This wrapper makes the $ jQuery short code avialable for code inside it.
Example:
(function ($, Drupal) {
$(".invisible").hide();
}(jQuery, Drupal));
This inserts a Drupal 8 JS behavior.
Example:
Drupal.behaviors.myBehavior = {
attach: function (context, settings) {
console.log('My Behavior');
}
};
These snippets are only made available in files with a .js
extension.
Make name consistent with related twig module
Initial release