Magento 2 – Get Image URL in PHTML File

image-urlmagento-2.1magento2magento2.2phtml

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

Best Answer

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'); 
Related Topic