Add a CMS block to Minicart Magento 2

Add a CMS block to Minicart Magento 2

August 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Add a CMS block to Minicart Magento 2

Adding a CMS Block to Minicart Magento 2: A Step-by-Step Guide

If you’re looking to add a CMS block to your Magento 2 minicart, you’ve come to the right place. In this guide, we’ll walk you through the entire process step by step, ensuring that even beginners can follow along.

Understanding the Minicart Process Flow

Before we dive into the code, let’s quickly review how the minicart works in Magento 2.

The minicart is rendered using a block called Magento_Theme/block/minicart and its corresponding template file vendor/magento/theme-frontend-blank/Magento_Theme/templates/html/topmenu/minicart.phtml.

When you add an item to the cart, it triggers an AJAX request which fetches data from the catalog_product_view controller. This controller then passes the product data back to the minicart block for rendering.

Locating and Editing Your Theme File

First, navigate to your custom theme directory in the file system. If you haven’t created a child theme yet, here’s how:

  1. Copy the Magento_Theme folder from app/design/frontend/Magento/luma to your project root.

  2. Rename it to match your theme name, e.g., mytheme.

  3. Open mytheme/Magento_Theme/templates/html/topmenu/minicart.phtml. This is where you’ll add the reference to your CMS block.

Adding the CMS Block Reference

Open the minicart.phtml file and locate this line:

<?php echo $block->getChildHtml('minicart.content') ?>

Here, you need to wrap it with a Magento_Cms_Block instance that references your specific CMS block.

Replace the existing line with this code snippet:

<?= $block->getLayout()->createBlock('Magento\Cms\Block')->setBlockId('your_block_id')->toHtml() ?>

Replace 'your_block_id' with the ID of the CMS block you want to display. You can find this in the Magento admin under Content > Pages.

Updating Your XML Layout File

Now, let’s update your theme’s XML layout file to include the new block in the minicart container.

  1. Navigate to app/design/frontend/<vendor>/<theme>/Magento_Theme/layout/default.xml.

  2. Add the following code inside the <body> tag:

<body>
    <referenceBlock name="minicart">
        <block class="Magento\Cms\Block" as="cms_block" template="Magento_Cms::block.phtml">
            <action method="setBlockId"><argument name="block_id" xsi:type="string">your_block_id</argument></action>
        </block>
    </referenceBlock>
</body>

Remember to replace your_block_id with the actual ID of your CMS block.

Clearing the Cache and Testing

After making these changes, don’t forget to clear your cache:

  • Run bin/magento cache:clean.
  • If you’re using a Varnish server, flush it as well.
  • Deploy static content by running bin/magento setup:static-content:deploy -f.

Now, when you access the frontend of your Magento 2 store, you should see your CMS block appearing in the minicart.

Conclusion

Adding a CMS block to the Magento 2 minicart is a straightforward process once you understand the flow and where to make the necessary adjustments. By following this guide, you’ve successfully learned how to:

  • Identify the relevant theme file for editing
  • Add a reference to the CMS block in your template
  • Update the XML layout file to include the new block

Remember that Magento 2 is designed with extensibility in mind, and most customizations can be achieved without core file modifications. Always check official documentation or trusted resources like Laravel Company for best practices.

Happy coding!

Magento 2 Checkout Catalog Themes

Our network