Posted about 5 years ago. Visible to the public.

Children of Anonymous Blocks are Orphaned

What a sad state of affairs. If a childs parent has no name, the child block becomes orphaned and alone, somewhere lost in Layout XML hell. To sort it, give the parent a name. The reason? The layout XML parser uses the name of the parent in XML to set the parent of the child block class instance, so if there is no name, the child is orphaned.

This won't work:

<block type="core/text_list"> <block type="core/template" template="a/valid/template.phtml" /> </block>

This will:

<block type="core/text_list" name="whatever_the_hell_you_want"> <block type="core/template" template="a/valid/template.phtml" /> </block>

Magento gives parent blocks an anonymous name, so this doesn't have to be the case. Children need not be orphaned, but that's just how it goes.

Owner of this card:

Mike Whitby
Last edit:
about 5 years ago
Posted by Mike Whitby to Magento
This website uses cookies to improve usability and analyze traffic.
Accept or learn more