0

I have created home.js file using require-config.js for HomePage.

And init that home.js file in home.phtml file for Home Page.

But i need to get the function that inside the home.js file into size.html file for Home Page.

var config = {
    map: {
        '*': {

            xxHomePage: 'XXX_HomePage/js/home-page'
        }
    }
};

In js file:

 getMsg: function () {
            return "HI";
        },

In Home.phtml file:

<div class="home-slider" id="home-slider" data-mage-init='{"xxHomePage":{}}' data-bind="blockLoader:true">

I need to get the 'getMsg' function into size.phtml (that also in home page

Is there any possible

How to do this ..

Thanks

2
  • Please share the code of home.js and and which function you want to call?
    – Amit Bera
    Commented Sep 20, 2018 at 7:23
  • also Provide require js code
    – Amit Bera
    Commented Sep 20, 2018 at 7:24

1 Answer 1

0

Add Below js at size.html

   require([
        'jquery',
        'XXX_HomePage/js/home-page'
    ],function($,homePage){      
        // call your function 

        console.log(homePage.getMsg());
    });
8
  • But size.phtml template is a ko template
    – Mahi M
    Commented Sep 20, 2018 at 7:34
  • then you want to call getMsg on window load ?
    – Amit Bera
    Commented Sep 20, 2018 at 7:42
  • Based on size.phtml 'div' visible in view port
    – Mahi M
    Commented Sep 20, 2018 at 8:10
  • Based on size.phtml what?
    – Amit Bera
    Commented Sep 20, 2018 at 8:23
  • shop-by-bra-size is sector , when dom will find data-bind="scope: 'shop-by-bra-size'" then XX_ShopBySize/js/shop-by-size initilize .devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…
    – Amit Bera
    Commented Sep 20, 2018 at 8:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.