Magento 2 provides a powerful way to manage content using CMS Static Blocks, which allow store owners to display reusable content across different pages. While you can manually add these blocks through the admin panel, a more efficient and scalable approach is to insert them using layout XML updates.
Using XML, you can easily position a static block within a layout without modifying template files, making it a cleaner and more maintainable solution. In this guide, we’ll walk through the process of adding a CMS Static Block to your homepage (or any other page) using XML layout updates. Whether you’re customizing your theme or managing multiple store views, this method ensures flexibility and consistency.
Let’s dive in!
These are the steps to add a CMS Static block to your homepage using XML Updates in XML files.
app/design/frontend/[VendorName]/[themeName]/Magento_Cms/layout/cms_index_index.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Cms\Block\Block"
name="iyngaran-s-home-content"
after="-">
<arguments>
<argument name="block_id"
xsi:type="string">your-static-block-identifier</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
NOTE: You can use “before” or “after” to place the block as you want.
That’s it!.
Clear cache and that should be it. Your static block should be displayed on the homepage.