Search code examples
phpmagento-layout-xmlmagento

Remove all blocks from Magento template


I want to remove all default blocks from the template/layout file of my custom Magento module. Currently I have used individual removes like

<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>

I want that the output from cart.phtml should not contain any code from Magento but it should only contain the code written in it.

Right now when I run http://127.0.0.1/mag/index.php/module/cart/ it outputs a complete HTML page with <html>, <head>, <body> and all other tags. How can I remove these tags? I want to get only the content written on module/cart.phtml.

Is there any way to remove/prevent the default layout rendering in Magento?


Solution

  • If you want to create a json response, you can just echo it from controller. If you are trying something else, this should help you:

    1. create a blank.phtml in your template's page folder. This file should have at least this line:

      <?php echo $this->getChildHtml('content') ?>

    2. in your layout put this code:

    <module_cart_index>

    <reference name="root">
        <action method="setTemplate"><template>page/blank.phtml</template></action>
    </reference>
    <reference name="content">
        <block type="checkout/cart" name="cp.cart" template="module/cart.phtml" />
    </reference>
    

    </module_cart_index>