📜  https:magento.stackexchange.com 问题 79708 magento-2-call-a-static-block-using-xml (1)

📅  最后修改于: 2023-12-03 15:31:20.613000             🧑  作者: Mango

Magento 2: Call a Static Block Using XML

In Magento 2, you can create and call a static block using XML. Here's how you can do it:

  1. Create a static block in the Magento Admin Panel.

  2. Note down the identifier of the static block that you just created.

  3. Open the layout XML file of the page where you want to display the static block.

  4. Add the following code to the layout XML file:

<referenceContainer name="container.name">
    <block class="Magento\Cms\Block\Block" name="block.name">
        <arguments>
            <argument name="block_id" xsi:type="string">identifier</argument>
        </arguments>
     </block>
</referenceContainer>

Replace 'container.name' with the name of the container where you want to display the static block. Replace 'block.name' with a name for the block. Replace 'identifier' with the identifier of the static block that you created in step 2.

  1. Save the changes to the layout XML file and clear the cache.

The static block should now appear on the page in the container specified in the XML file.

That's it! With this code, you can easily create and call a static block using XML in Magento 2.