【问题标题】:How to display image from theme folder in .phtml file如何在 .phtml 文件中显示主题文件夹中的图像
【发布时间】:2019-11-20 14:23:09
【问题描述】:

我正在尝试在我的 phtml 文件中显示图像,但我似乎无法加载它。下面是我的代码

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

现在我要加载的图像位于

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

但我似乎无法加载此图像。有什么想法吗?

【问题讨论】:

    标签: magento magento2


    【解决方案1】:
    1. Vendor/theme/Vendor_Module/web/images/filename.pngapp/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. 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-07
      • 1970-01-01
      • 2013-11-13
      • 2013-11-18
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 2011-09-11
      相关资源
      最近更新 更多