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 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 SolutionsMagento2 – How to Add New CSS File for a Module In the latest beta version for Magento 2 there is no more head block. The head, content and other blocks are defined as containers. should remove the <referenceBlock name="head"> section and instead add this inside the <head> tag (where you added the page title) <css src="Magento_Hello::css/custom.css"/> so your <head> tag should look like this: <head> <title>Hello World</title> <css src="Magento_Hello::css/custom.css"/> </head> Magento 2 – How to Call Custom Module Phtml File in CMS Page {{block class="Magento\Framework\View\Element\Template" template="Testing_Helloworld::helloworld.phtml"}} you can use Magento\Framework\View\Element\Template block class to call custom phtml files with out define block class. Related TopicLoading a .phtml File Within an Observer in Magento 2Magento 2 – How to Get the URL of a New Module
Best Answer
For example your image at:
Use
$block->getViewFileUrl()
function to get image url in phtml file like this