You can use below two methods to display images from theme folder in phtml file in Magento 2. Often times it’s very convenient to keep the theme related images to theme images folders.
Option #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
Option #2
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
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply