Remove all blocks from Magento template

Remove all blocks from Magento template

August 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Remove all blocks from Magento template

Removing All Blocks from Magento Layout: A Comprehensive Guide

As a Magento developer, you might face situations where you want to remove all default blocks from your custom module’s layout file. This allows you to have more control over the page structure and display only the content you desire.

Understanding the Current Issue

You’ve shared a snippet of your current layout configuration:

<module_cart_index>
   <remove name="head" />
   <remove name="header" />
   <remove name="footer" />
   <remove name="right"/>
   <remove name="left"/>
   <remove name="cart_sidebar" />
   <remove name="checkout.cart" />
   <remove name="sale.reorder.sidebar" />
    <reference name="content">
        <block type="checkout/cart" name="cp.cart" template="module/cart.phtml" />
    </reference>
</module_cart_index>

This configuration removes several default blocks from the cart index page. However, when you access http://127.0.0.1/mag/index.php/module/cart/, it still renders a complete HTML page with all the standard tags like <html>, <head>, and <body>.

The Goal: Displaying Only Custom Content

Your objective is to remove the default layout rendering in Magento so that only the content written in module/cart.phtml appears on the page. You want to strip away all the HTML framework generated by Magento.

The Solution: Control Over Layout Rendering

To achieve this, you need to take control over the layout rendering process. Here are several steps you can follow:

1. Use a Custom Template

In your layout configuration, you’re already using module/cart.phtml as the template for the content block. This is a good start.

<reference name="content">
    <block type="checkout/cart" name="cp.cart" template="module/cart.phtml" />
</reference>

2. Prevent Default Layout Rendering

To prevent Magento from rendering its default layout, you need to override the renderLayout() function in your module’s core file. This is a bit advanced and requires understanding of Magento’s controller architecture.

Here’s an example:

public function indexAction()
{
    $this->loadLayout();
    $this->renderLayout(false); // Set the second parameter to false
}

In this code, we’re calling loadLayout() as usual, but when rendering the layout, we pass false as a second argument. This tells Magento not to render the default layout.

3. Display Only Custom Content

With the default layout removed, only your custom content in module/cart.phtml will be displayed on the page. However, you need to ensure that this file is properly structured and contains all the necessary HTML tags for a complete page.

For example:

<html>
<head>
    <!-- Your head section with meta tags, CSS links, etc. -->
</head>
<body>
    <!-- Your main content here -->
</body>
</html>

Best Practices

Remember to test your changes thoroughly in different browsers and devices to ensure the layout is responsive and displays correctly.

For more advanced customizations, consider using Magento’s page template feature or creating a new page type. You can find detailed guides on these topics in the Laravel Company Blog.

Conclusion

Removing all default blocks from your Magento layout requires a combination of layout configuration and core file overrides. By following this guide, you should be able to display only your custom content while still benefiting from Magento’s layout system.

This approach offers greater control over your page structure but requires careful handling of HTML tags in your custom templates. Always test your changes thoroughly to ensure they don’t break the functionality of other modules or pages on your site.

Happy coding! Let us know if you have any further questions or need more specific examples.

Checkout Indexing Extensions Themes

Our network