I am getting a block twice in Magento?

丶灬走出姿态 提交于 2019-12-07 01:38:37

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7979149/i-am-getting-a-block-twice-in-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!