Magento – Content shows up two times

blocksmagento-1.9module

I just created a module and I put this in my layout file:

<?xml version="1.0"?>
<layout version="0.1.0">
    <filteredproducts_index_index>
        <reference name="root">
            <action method="setTemplate">
                <template>page/2columns-left.phtml</template>
            </action>
        </reference>
        <reference name="content">
            <block type="filteredproducts/myblock" name="myblock" template="test.phtml"/>
        </reference>
    </filteredproducts_index_index>
</layout>

Now for some reason, no mather what block I put there inside my reference name="content" tag. The block is shown twice.

test.phtml:

<?php
    echo "test";
?>

IndexController.php:

<?php
class Brightinsight_FilteredProducts_IndexController extends Mage_Core_Controller_Front_Action
{

    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }

}

The text shown at the page is testtest.
So the content must be loaded two times for some reason I just can't seem to figure out how.
Any help appreciated.

Best Answer

Given your layout / controller combination, the only things I can think of that could cause the output to occur twice are:

  1. The page/2columns-left.phtml template renders the content block twice (or the content block and manually an instance of filteredproducts/myblock).
  2. There's an event observer than it manually rendering out the additional block.
  3. You are injecting your custom phtml file test.phtml into the layout elsewhere as well as in that layout file. Perhaps some initial debug code in one of the core layout files.
  4. Your block definition extends Mage_Core_Block_Template but has additional render code in one of the rendering methods that manually renders, but still calls the parent method.
Related Topic