添加块 magento2

Add block magento2

如何在magento标准magento Luma主题的左侧边栏添加一个带图片的块,如图

我试过这个方法

app/design/frontend/TestTheme/Theme/Magento_Catalog/layout/catalog_product_view.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="catalog.compare.sidebar">
            <action method="setPageTitle">
                    <argument name="logo_file" xsi:type="string">images/logo.svg</argument>
                    <argument name="logo_img_width" xsi:type="number">200</argument>
                    <argument name="logo_img_height" xsi:type="number">200</argument>
            </action>
        </referenceBlock>
    </body>
</page>

但这行不通

Magento_Theme
---layout
-----default.xml
---youtemps
-----img.phtml

mb 不是最好的实现,但是这个方法会给你带来文字,不幸的是图片我不能告诉你如何在没有演示的情况下显示。

我希望你能知道如何改进方法,或者尝试根据我的代码完成我的任务。

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="sidebar.additional">
            <container name="sidebar.img.container" htmlClass="pseudo-container" htmlTag="div">
                <block class="Magento\Framework\View\Element\Template" name="testtest.sidebar.sell" as="sell_lable" template="Magento_Theme::youtemps/img.phtml" before="-"/>
            </container>
        </referenceContainer>
    </body>
</page>

更新,在您的 phtml 文件中添加此代码

<h2 style="margin: 0">hot price</h2>
<img src="<?php echo $this->getViewFileUrl('images/sell-sidebar.jpg'); ?>" style="margin-bottom: 10px" alt="" />

在你的 Magento_Theme 文件夹中添加图像文件夹并将你的图像放入文件夹,然后插入到 getViewFileUrl('images/sell-sidebar.jpg'); 它的路径相对 Magento_Theme