How can we get Magento 2 base URL in web template (.html file) ?
Note: I am talking about web template (.html file). Not about general templates file (.phtml file).
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityHow can we get Magento 2 base URL in web template (.html file) ?
Note: I am talking about web template (.html file). Not about general templates file (.phtml file).
=> Set URL in the JS file :
First of all, Add mage/url
to the list of dependencies.
Then, Add the following function to the knockout JS file:
getBaseUrl: function() {
return url.build('<modulename>/<controllername>/<actionname>');
},
=> Use Knockout to set the href :
<a data-bind="attr: { href: getBaseUrl() }">Link Text</a>
Then, clear Varnish and browser cache.