How to specify skin image path in Knockout HTML template?
You need to call the function
into js
from the template.
require.toUrl('images/icon-paypal.png');
If you are trying to add just an image path in phtml file, you should follow below way,
<img src="<?php echo $block->getViewFileUrl('images/image.png') ?>">\
To do this with Knockout way:
Try adding a variable to window from *.phtml file:
<script>
window.imgpath = '<?php echo $block->getViewFileUrl('images/image.png') ?>';
</script>
and reading that variable from window:
function someFunction() {
var imgPath = window.imgpath;
}
Change your image code :
<img alt="" data-bind="attr: { src: someFunction() } "/>
create js variable in phtml
<script>
var imgpath = '<?php echo $block->getViewFileUrl('images/image.png') ?>';
</script>
Now create new js function
getImagepaypal: function() {
return window.imgpath;
}
in you html file
<img alt="" data-bind="attr: { src: getImagepaypal() } "/>