MadzQuestioning
MadzQuestioning

Reputation: 3772

How to display image from theme folder in .phtml file

I'm trying to display an image in my phtml file but I can't seem to load this. Below is my code

<!--- Location: /app/design/frontend/Vendor/Module/Magento_Theme/templates/html/custom-page.phtml -->
<div>
    <img src="{{view url='images/v3.jpg'}}"/>
</div>

Now the image I'm trying to load is located in

/app/design/frontend/Vendor/Module/web/images/v3.jpg

But I can't seem to be able to load this image. Any idea guys?

Upvotes: 0

Views: 2968

Answers (1)

BaoPV
BaoPV

Reputation: 21

  1. Images in Vendor/theme/Vendor_Module/web/images/filename.png or app/code/Vendor/Module/view/frontend/web/images/filename.png
<img src="<?= $this->getViewFileUrl('Vendor_Module::images/filename.png'); ?>"> //phtml

<img src="{{view url='Vendor_Module::images/image.png'}}"/> //cms block/ cms page
  1. Images in Vendor/theme/web/images/filename.png
<img src="<?= $block->getViewFileUrl('images/filename.png'); ?>" /> //phtml

<img src="{{view url='images/image.png'}}"/> //cms block/ cms page

Upvotes: 2

Related Questions