1

I'm new to Magento, and am wondering what the reference tag is for in the [mylayout].xml file.

<reference name="root">
    <block type="dennis/mijnblok" name="content" output="toHtml" template="oefening/all/Mijnblok.phtml" />
</reference>

If I change reference name to content it will not work.

But, when I change name="content" to name="test", it does work.

So I'm wondering why, can anyone explain?

2

reference meaning you are going to using the already defined block.

By default all pages has following block

1.Header 2.Content 3.Left 4.Right 5.Footer

If you want to inculde some thing in the content block you use as content block as reference

<your_handle>
   <reference name="content">
     <!-- your block code -->
           <block type="dennis/mijnblok" name="block.unique.name" template="oefening/all/Mijnblok.phtml" />

   </reference>
</your_handle> 

Note : Block name must be unique

Refer this Tutorial you will get better understanding of the layout in magento

  • Thanks, but why is the root name always working, and the content name not? – Refilon Nov 16 '15 at 13:34
2

I think this will be because "content" is actually the main content area in which you should be putting your Mijnblok.html

app/design/frontend/base/default/layout/page.xml

<default translate="label" module="page">
    <block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
        <block type="core/text_list" name="content" as="content" translate="label">
            <label>Main Content Area</label>
        </block>
    </block>
</block>
2

Reference element is used to link an already defined block in any layout XML. To add any child block to an existing block, to modify attributes of an existing block or to perform any action on an existing block, the reference element is used to link to the existing block. The reference element must have a name attribute which refers to the existing block’s name.

name="root"
name="head"
name="left"
name="right"
name="content"
name="footer"
and etc

These are predefined block in magento. you cannot use that name as a block name. if you use that then there is name conflict and your block will not shown.

  • Can't find root as a block? – Refilon Nov 16 '15 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.