1

I have added my script as follows in template :

<script type="text/x-magento-init">
{
    "*":{
        "Vendor_Module/js/myscript":{
            "baseUrl": "<?php echo $quickshopHelper->getBaseUrl() ?>",
            "qsLabel": "<?php echo $quickshopHelper->getQuickShopLabel() ?>",
            "itemClass": "<?php echo (!empty($itemClass))?$itemClass:"" ?>",
            "target": "<?php echo (!empty($target))?$target:".product-item-info"; ?>",
            "autoAddButtons":<?php echo ($autoAddButtons==1)?"true":"false" ?>
            }
    }
}
</script>

I have called the template in default.xml cause I want it everywhere in frontend. Its working fine on page load but on certain pages when ajax call is made, my script doesn't work. I tried on the same template to trigger mage using below code but it's not working.

<script>
require([
    'jquery'
], function ($) {

        $('.main').trigger('contentUpdated');
});
</script>

And yes the selector is in another module and not my template. I have almost referred everything I could find related to this declarative notation but could not find the solution yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.