Add a static image on PHTML page and CMS Blocks : Magento2
image url Syntax is ok for both static block
and phtml
, But make sure that when you write this code in static block
<img src="{{view url="images/slide-bg.jpg"}}" alt="test" />
on front end it looks like
http://localhost/magento2new/pub/static/frontend/Magento/luma/en_US/images/slide-bg.jpg
Where Magento/luma
is package
name and theme
name, you can replace with your package
and theme
name
So you have to take care for slide-bg.jpg
is exist in
pub/static/frontend/Magento/luma/en_US/images
directory.
In your case,
<img src='<?php echo $this->getViewFileUrl('images/footer-logo.png'); ?>' alt="Demo">
Syntax seems ok , but in frontend It looks like
http://localhost/magento2new/pub/static/frontend/Magento/luma/en_US/images/footer-logo.png
So you have to make sure that footer-logo.png
exist in
pub/static/frontend/Magento/luma/en_US/images
directory.
And don't forgot about "[quotation marks]
For your custom module create a directory structure like
Company/Module/view/frontend/web/images/image-icon.png
and in phtml use following code
<img src='<?php echo $this->getViewFileUrl('Company_Module::images/image-icon.png'); ?>' alt="image-icon" width="30" height="25">
Easy solution:
Put your image on Your Magento 2 Path:
/app/design/frontend/< Vendor >/< theme >/web/images
Use this code to call the image in phtml file:
echo $block->getViewFileUrl('images/demo.jpg');