I want to get media url like abc.com/store/pub/media/ (site url like abc.com/store .) in My ko template(.html) file.

we can use require.toUrl(''); for static view file. same way i want to get media view file


I used a dirty code to get the media URL in any HTML file. You can use a better way if you want but this is a simple and dirty solution :)

Add following code to



    window.getMediaUrl = "<?= $block->getBaseUrl() . 'pub/media/' ?>";

Now you can get media URL in any HTML file as given below

<span data-bind="text: window.getMediaUrl" ></span>

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.