1

How should I include myscript.js to my module.

the content of requirejs-config.js:

var config = {
 map: {
 '*': {
 'Magento_Checkout/template/minicart/item/default.html':
 'vendor_modulename/template/minicart/item/default.html',
 ??? --> how add myscript.js
 }
 }
};

myscript.js?

asked Nov 17, 2016 at 12:54

2 Answers 2

1

requiredjs-config.js :

var config = {
map: {
 '*': {
 'Magento_Checkout/template/minicart/item/default.html':
 'vendor_modulename/template/minicart/item/default.html',
 "<js_reference>":"<your_js_path>/myscript.js"
 }
}

};

Ex. 'Magento_Checkout/js/model/shipping-save-processor/default': '<namespace>/js/model/shipping-save-processor/default'

And use in template to use it same as you require other js .

answered Nov 17, 2016 at 13:01
2
  • May you provide me more guide, how to pass the flag from myscript.js to default.html? my initObservable: function () does not work Commented Nov 17, 2016 at 13:09
  • using data-bind with the element you can bind your js to html element and than write knockout template code in it. Commented Nov 17, 2016 at 13:12
1

requirejs-config.js :

var config = {
 map: {
 '*': {
 js_reference: 'Namespace_Module/myscript.js'
 }
 }
};

In your phtml file:

<script type="text/javascript">
require(['jquery','myscript.js'],function($){
 });
</script>
Keyur Shah
18.1k6 gold badges68 silver badges80 bronze badges
answered Nov 17, 2016 at 13:19
2
  • In "html" file, there is no phtml! Commented Nov 17, 2016 at 13:23
  • i didn't check in html but try this in html. hopefully it helps Commented Nov 18, 2016 at 5:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.