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
Zinat
2,0992 gold badges31 silver badges53 bronze badges
2 Answers 2
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
Ronak Chauhan
6,2133 gold badges31 silver badges67 bronze badges
-
May you provide me more guide, how to pass the flag from myscript.js to default.html? my initObservable: function () does not workZinat– Zinat2016年11月17日 13:09:04 +00:00Commented Nov 17, 2016 at 13:09
-
using
data-bindwith the element you can bind your js to html element and than write knockout template code in it.Ronak Chauhan– Ronak Chauhan2016年11月17日 13:12:55 +00:00Commented Nov 17, 2016 at 13:12
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
Sameer Bhayani
1,90621 silver badges34 bronze badges
-
In "html" file, there is no phtml!Zinat– Zinat2016年11月17日 13:23:22 +00:00Commented Nov 17, 2016 at 13:23
-
i didn't check in html but try this in html. hopefully it helpsSameer Bhayani– Sameer Bhayani2016年11月18日 05:26:10 +00:00Commented Nov 18, 2016 at 5:26
default