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?

Fabian Schmengler
66.2k25 gold badges191 silver badges422 bronze badges
asked Jul 16, 2015 at 13:16

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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.