How I can Add a static image on PHTML page and CMS Blocks into Magento2?
in Magento 1.x it was possible using $this->getSkinUrl('images/xyz.jpg')
I am trying following method into Magento2
In Phtml File:
<img src=”<?= $block->getViewFileUrl(‘images/footer-logo.png’); ?>” alt=”Demo” />
In CMS Blocks:
<img src=”{{view url=”images/slide-bg.jpg”}}” alt=”” />
but it's not working properly. Please suggest me my mistakes
Best Answer
image url Syntax is ok for both
static block
andphtml
, But make sure that when you write this code in static blockon front end it looks like
http://localhost/magento2new/pub/static/frontend/Magento/luma/en_US/images/slide-bg.jpg
Where
Magento/luma
ispackage
name andtheme
name, you can replace with yourpackage
andtheme
nameSo you have to take care for
slide-bg.jpg
is exist inpub/static/frontend/Magento/luma/en_US/images
directory.In your case,
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 inpub/static/frontend/Magento/luma/en_US/images
directory.And don't forgot about
"[quotation marks]