5

My current understanding of defining layout blocks is that if I do:

<block type="core/template" name="a.b" as="aB" template="some.phtml">
    <block type="x/y" name="c.d" as="cD" />
</block>

then I've added c.d as a child block of a.b, and from within some.phtml I can call $this->getChildHtml('cD'); to ask c.d to render its output at that position in the template.

I was looking around in catalog.xml, and I've just come across the syntax:

<action method="append"><block>block.name</block></action>

so I followed it to see what's different from the previous method:

public function append($block, $alias = '')
{
    $this->insert($block, '', true, $alias);
    return $this;
}

....

public function insert($block, $siblingName = '', $after = false, $alias = '')

append implies ordering the child block at the end of the parent block, but I could have easily done that with an after="-" parameter in the first method.

So, what's the difference between these two methods of adding a child block to a parent block?

1 Answer 1

4

append appends an existing block that is referenced by name, to a new parent. It can be used to move a block to another location or to duplicate it.

<block> always creates a new block.

2
  • 1
    So <block> creates a new instance, while append simply manipulates an existing instance?
    – pcronin
    Commented Jul 16, 2015 at 13:35
  • Yes. Exactly. Correct. Commented Jul 16, 2015 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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