I try to add a script tag with a console.log("hello world"); message in the knockoutjs template vendor/magento/module-checkout/view/frontend/web/template/cart/shipping-rates.html

This is the template for the cart summary in the cart. ( the sidebar at the right side ) where the shipping methods are showing if you expand that section

enter image description here

I just added this code at the end of the file:

    console.log("Hello world!");

Then I flushed the cache and also flushed the browser cache and reloaded the site, but the console log is not showing if the shipping methods load.

The script tag is in the source code, but it is not executed.


This goes against the whole point of using Knockout, I suspect it will never work as either KO or Magento are preventing it from being invoked.

But regardless, you shouldn't be adding script tags here. What is it you're trying to achieve?

Most likely you will be better off using the afterRender method to invoke your function.

<div afterRender="yourComponentFunctionHere"></div>

Your Answer

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

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