A
A
Andrey Okhotnikov2019-01-16 15:12:24
JavaScript
Andrey Okhotnikov, 2019-01-16 15:12:24

How to work with JS in Magento?

I figured out how to include scripts in phtml template files with require js, this is understandable. But in magento there is a way to connect via x-magento-init, I didn’t understand from the documentation in which cases to use this method and where should the included file be located?
I connect like this

<script type="text/x-magento-init">
{
    "*": { 
        "Magento_Catalog/js/product/counter.js": {}
    }
}
</script>

Where to place the counter file?
And in what cases should I use require in the js file, and in which define?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question