JavaScript

Magento 2 Knockout Translation Bug

Many bugs have been submitted to the Magento 2 Github page, and whilst lots have been fixed, there are many waiting to be fixed and included in upcoming versions. None more so than the Magento 2 knockout translation bug.
This bug is fairly easy to replicate in a blank install of Magento 2, and can …

Different Ways of Using JavaScript in Magento 2

This post will demonstrate the different ways of using JavaScript in Magento 2, specifically adding them through various methods that Magento provides. There is also the ability to extend of override existing JavaScript. Here will show you how.
To include local and external JavaScript in layout XML similar to Magento 1, you can edit your …

Adding JavaScript in Magento 2

There are currently three ways of adding JavaScript in Magento 2 using RequireJS, which are presented by the three JS module types: plain module, jQuery widget and UIComponent.
Each type will require you to have set up a basic Magento module structure, including a requirejs-config.js file. For example, let’s assume that a custom.js file is …

Magento 2 RequireJS

Magento 2 makes use of RequireJS, which is a JavaScript module loader and thus eliminates the need to add your JavaScript files in a particular order.
In Magento 1, adding JavaScript files in a particular order could prove tricky. An example of this is needing to add a jQuery plugin JavaScript file after firstly …

Add Custom JS in Magento 2

After creating a custom theme, developers will look at how to add custom JS in Magento 2.
Within Magento 1, in your custom theme you could specify a local.xml layout file that contained all of layout updates.
Within this file, you could add JS files using the following code snippet.
The code above assumes …