Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am getting a block twice in Magento?

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.

like image 753
ScoRpion Avatar asked Nov 02 '11 10:11

ScoRpion


People also ask

What are Magento 2 blocks?

Magento block is a modular unit of content that can be placed anywhere on the page. Blocks in Magento are referred to as static blocks or CMS blocks. They help to display fixed information such as text, images, and embedded video, as well as dynamic information from a widget that originates through the database.

How many types of blocks Magento?

There are two phases of the block life cycle: generating blocks and rendering blocks.

What is the functional difference of block & container in Magento 2?

Containers represent the placeholders within that web page structure (2). And blocks represent the UI controls or components within the container placeholders (3).


1 Answers

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.

like image 196
benmarks Avatar answered Oct 20 '22 01:10

benmarks