Skip to main content

Posts

Showing posts with the label template

Magento 2 add images in knockout files

If you want to add a dynamic image from the theme or module’s web/images folder, You can be assigned images using the knockout template with ease. Simply call the function in src of your image tag, require.toUrl(‘web/images’) Keep the image in web/images/logo.png location of your theme or module. <img data-bind="attr: { src: require.toUrl('images/pawan.png') }" /> Now simply add above one line in .html template to display the image on your page.  Using this method, Your images search for the theme web/images folder. If you want to display Images from specific Module’s Web folder: If you have images in the module web folder in your theme or Custom module, app/design/frontend/{Vendor}/{themename}/Magento_Checkout/web/images/logo.png You have to add module name before image path, <img data-bind="attr: { src: require.toUrl('Magento_Checkout/images/logo.png') }" /> When you see the front page, your images have taken a path from the pub/static