How to Call a Static Block in XML in Magento 2

Static blocks in Magento 2 allow store owners to create reusable content, such as banners, promotional messages, and custom HTML, and place them in various locations across their site. For developers, knowing how to call a static block in XML is essential for better content management and improved store customization. This guide shows you the steps to quickly add a static block to specific layout areas using XML in Magento 2.

What is a Static Block?

In Magento 2, a static block is a pre-configured block of content managed via the admin panel. Once created, it can be called directly in XML layout files, making it ideal for placing custom content on specific pages or sections of your store.

Calling a Static Block in XML

To display a static block in Magento 2 using XML, follow these steps.

1) Identify the Block’s Container
Choose the area where you want to display the block, such as the main content area, header, or footer.

2) Use the XML Code

Replace "content" with the desired container (header, footer, etc.), and set "your_block_identifier" to match the unique identifier of the static block created in the admin.

3) Clear Cache
After updating the XML file, clear the Magento 2 cache to see the changes reflected on the front end.

Example: Adding a Static Block to the order success page

By using static blocks, you can easily manage promotional banners, announcements, and custom HTML without modifying your theme files every time. This approach saves time and makes content updates more flexible, especially for non-developers. Whether you’re customizing the footer, header, or main content area, following these steps will give you more control over the layout and appearance of your Magento 2 site.

Feel free to explore other ways to enhance your Magento 2 store by combining static blocks with dynamic content strategies.

Happy customizing!

P.S. Do share this note with your team.

You may also like:

Magento 2: How to use helper in PHTML?

Magento 2: How to get a dynamic Base URL Path in XML?

How to remove/disable add to compare in Magento 2?

Leave a Reply

Your email address will not be published. Required fields are marked *