Remove all blocks from Magento template

4.6k views Asked by At

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?

2

There are 2 answers

6
Emi On BEST ANSWER

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>

0
Louis B. On

This is how Magento does it, in app/design/adminhtml/default/default/layout/api2.xml:

<adminhtml_api2_role_grid>
    <remove name="root"/>
    <block type="api2/adminhtml_roles_grid" name="api2_roles.grid" output="toHtml"/>
</adminhtml_api2_role_grid>

So to get this to work with your custom block, do something like this:

<some_layout_handle>
    <remove name="root"/>
    <block type="customextension/block_name" template="some-template.phtml" output="toHtml"/>
</some_layout_handle>

This works for me, the only content output is what my template/block generates. I assume the block might have to extend Mage_Core_Block_Template for this to actually work.