image path for a phtml file
Domanda
Hello I would like to add a image to a phtml file. however it didn't get use to the magento code to get the image path
<img src="{{media url='/ca_flag.png'}}"/>
Somehow the image address was translate to something like this
www.domain.com/%7B%7Bmedia%20url='/ca_flag.png'%7D%7D
what should I use?
Thanks
Soluzione
For template files:
Images in Vendor/theme/Vendor_Module/web/images
or app/code/Vendor/Module/view/frontend/web/images/
<img src="<?php echo $this->getViewFileUrl('Vendor_Module::images/image.png'); ?>" />
or if images are in Vendor/theme/web/images/
<img src="<?php echo $block->getViewFileUrl('images/image.png'); ?>" />
For CMS Static Blocks or Pages:
Images in Vendor/theme/Vendor_Module/web/images
or app/code/Vendor/Module/view/frontend/web/images/
<img src="{{view url='Vendor_Module::images/image.png'}}"/>
or if images are in Vendor/theme/web/images/
<img src="{{view url='images/image.png'}}"/>
Altri suggerimenti
Put your image inside app/design/frontend/Vendor/Theme/web/images and call it like -
<img src='<?php echo $this->getViewFileUrl('images/demo.png'); ?>' alt="Demo">
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange