Override itemrender in block - Magento

Override itemrender in block - Magento

August 23, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Override itemrender in block - Magento

Overriding Item Render in a Magento Block

Hello developers! Today we’re going to tackle a common question for Magento beginners: how to override an item render in a block using layout XML files.

Understanding the Layout XML Structure

Let’s first break down the given layout XML code:

<block type="checkout/cart" name="checkout.cart">
    <action method="setCartTemplate"><value>checkout/cart.phtml</value></action>
    <action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
    <action method="chooseTemplate"/>
    <action method="addItemRender">
        <type>simple</type>
        <block>checkout/cart_item_renderer</block>
        <template>checkout/cart/item/default.phtml</template>
    </action>
    <!-- More item renders here -->
</block>

This block is of type checkout/cart and has several actions:

  1. It sets the cart template to checkout/cart.phtml.
  2. It sets the empty template (when no items are in the cart) to checkout/cart/noItems.phtml.
  3. It chooses a template for rendering.
  4. It adds an item render for simple products, using the renderer block checkout/cart_item_renderer and the template checkout/cart/item/default.phtml.

The Challenge: Overriding an Item Render

Our goal is to override the addItemRender action for simple products with a custom template. Since we’re dealing with an action method being called in the XML, this isn’t immediately obvious.

The Solution: Using Layout XML Updates

To override the item render, you need to create your own layout XML update file in your theme or module’s app/design/frontend/Your_Theme/layout directory (or equivalent path if using a custom theme).

In this new file, you define an <update> node referencing the original block and add your custom addItemRender action.

Here’s how to do it:

  1. Create a new XML file, let’s say catalog_category_view.xml.
  2. Add the following content:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <!-- This is where we add our update -->
        <referenceBlock name="checkout.cart">
            <action method="addItemRender">
                <type>simple</type>
                <block>Your_Custom_Module/checkout_cart_item_renderer</block>
                <template>Your_Theme/Magento_Checkout/item/default.phtml</template>
            </action>
        </referenceBlock>
    </body>
</page>

In this example, we’re referencing our custom module’s renderer block (Your_Custom_Module/checkout_cart_item_renderer) and the path to our custom template file in the theme (Your_Theme/Magento_Checkout/item/default.phtml).

  1. Make sure your custom renderer block extends Magento\Checkout\Block\Cart\Item\Renderer or a similar base class.

Testing Your Customization

After creating the layout XML update and the necessary templates/blocks:

  1. Run bin/magento cache:flush.
  2. Visit your checkout cart page.
  3. Check if the new template is applied to simple items as expected.

Remember, Magento follows a “theme first” approach for layout updates. If you have multiple themes enabled, ensure your customizations are applied in the active theme’s scope.

Conclusion

Overriding item renders in Magento blocks requires understanding how action methods work in layout XML files and utilizing the addItemRender method correctly. By creating a custom layout XML update file with the appropriate <referenceBlock> and <action>, you can successfully override the item render for simple products (or any other product type) with your own template.

Feel free to explore more advanced techniques like using layout plugins or XML config files at https://laravelcompany.com/blog/tag/magento-2-layout for further customization. Happy coding!

Remember: Always backup your Magento installation before making any significant changes, and thoroughly test your modifications in a development environment before deploying them to production.

That’s it! Let me know if you have any other questions about Magento layout updates or need help with specific code examples.

Checkout Catalog Themes

Our network