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


enter image description here

This is my directory structure of Helloworld Module

  • Let me know if you have any issue Aug 19, 2017 at 16:26
  • I add images like above but its not working sir. i cleared my cache but not working
    – Hemal
    Aug 19, 2017 at 16:34
  • What is the error or what is display in image URL? Aug 19, 2017 at 16:48
  • nothing show just text
    – Hemal
    Aug 19, 2017 at 16:53
  • is there any other solution
    – Hemal
    Aug 19, 2017 at 17:19

4 Answers 4


For example your image at:


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

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

Use Module image : $block->getViewFileUrl('Vendor_Module::images/test.jpg');

Use Theme image : $block->getViewFileUrl('images/test.jpg');


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"}}


in case if u have enabled opcache in your php.ini u will not see immediately the result. Also the images from the module are not added into pub/static folder. therefore to clear opcache do:

systemctl restart php<<version.minor>>-fpm i.e. systemctl restart php7.4-fpm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.