I am getting a block twice in Magento?
Asked Answered
D

1

7

I am trying to create product block on home page where in I copied page.xml to my theme's layout folder and modified it like

<page_two_columns_left translate="label">
<label>All Two-Column Layout Pages (Left Column)</label>
<reference name="root">
    <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
    <!-- Mark root page block that template is applied -->
    <action method="setIsHandle"><applied>1</applied></action>
</reference>
<reference name="content">
   <block type="core/template" name="mycategories" output="toHtml" template="sweet/sweet.phtml"/>
 </reference>

Here I was expecting one one block in the middle of my Home page and i am getting that but in addition to this i am getting one more block (same as this block sweet.phtml) at the bottom of home page.. below the footer link. Can anyone tell me whats the problem.

Disparate answered 2/11, 2011 at 10:54 Comment(1)
Are you trying replace some block named mycategories with your one?Roomful
B
12

You've marked your block as an output block. When the view is rendered via renderView() in the controller action, your block is both a child of a block which echoes its children (content is a core/text_list block), as well as being an output block which will be rendered in its own right.

Remove the output="toHtml" bit and you will have what you need. By the way, you could / should move this change from a custom page.xml and into a local.xml file in your layout - it need only be inside a <page_two_columns_left /> layout update handle.

Bendicta answered 3/11, 2011 at 4:30 Comment(2)
Great And Thank you... I have copied page.xml into my folder and it gets over ridden. i am making changes there only. Isn't it fine?Disparate
Well, it interferes with the upgrade path. Ideally this kind of change would be made in a local.xml file in your theme's layout folder and you would leave page.xml where it is. Your local.xml would therefore contain <layout><page_two_columns_left><reference name="content"><block type="core/template" name="mycategories" output="toHtml" template="sweet/sweet.phtml"/> <.../>Bendicta

© 2022 - 2024 — McMap. All rights reserved.