我想在我网站的顶部提供优惠按钮。为此,我想创建phtml文件,并希望在magento2布局xml文件中调用它。请告诉我如何在magento2中实现这一目标?
答案 0 :(得分:4)
Magento 2 call" cms block"在XML文件中:
<block class="Magento\Cms\Block\Block" name="block_name">
<arguments>
<argument name="block_id" xsi:type="string">block_identifier</argument>
</arguments>
</block>
Magento 2 call&#34; cms block&#34;在Phtml文件中:
<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>
Magento 2 call&#34; cms block&#34;在CMS内容中:
{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
它工作正常......
答案 1 :(得分:0)
试试这个:所有的layput和模板文件应该在View文件夹中
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/layout_generic.xsd">
<container name="root" label="Root">
<block class="Namespace\Module\Block\Adminhtml\Edit\Tab\View\XYZ" name="module.edit.tab.xyz" template="Namespace_Module::/template_path/abc.phtml"/>
</container>
</layout>
答案 2 :(得分:0)
您只需要用块标识符替换即可...
这是我的区块标识符=“ product_view_right_sidebar” == “ Your_block_identifier”
<referenceContainer name="sidebar.additional">
<block class="Magento\Cms\Block\Block" name="product_view_right_sidebar">
<arguments>
<argument name="block_id" xsi:type="string">product_view_right_sidebar</argument>
</arguments>
</block>
</referenceContainer>