Question

I'm trying to add an image to my first module can someone tell me how I cando this I am new to Magento

this is phtml file

<h2>Hello world</h2>

module is in

app/code/Test/Helloworld

enter image description here

This is my directory structure of Helloworld Module

Was it helpful?

Solution

For example your image at:

app/code/Vendor/Module/view/frontend/web/images/demo.jpg

Use $block->getViewFileUrl() function to get image url in phtml file like this

echo $block->getViewFileUrl('Vendor_Module::images/demo.jpg'); 

OTHER TIPS

If you using phtml file add an image, CSS and js use $block->getViewFileUrl() and if you working on block use this{{view url="images/IMG_7300.JPG"}}

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top