3

I would like to understand when (and why) should I use <action method="insert">...</action> instead of using <block type="... />.

Example: move cart sidebar from left to right column :

1/

<reference name="left">
 <action method="unsetChild">
  <blockName>cart_sidebar</blockName>
 </action>
</reference>

2.1/

<reference name="right">
 <block type="checkout/cart_sidebar" name="cart_sidebar" tempalte="checkout/cart/sidebar.phtml" />
</reference>

2.2/

<reference name="right">
 <action method="insert">
  <blockName>cart_sidebar</blockName>
 </action>
</reference>

2.1 or 2.2 ?

Thanks

Lanks
  • 514
  • 4
  • 17

1 Answers1

5

I think that you should use the insert action when you want to move a block that was already added to the layout. For the example you gave it should be something like this:

<reference name="left">
  <action method="unsetChild">
    <name>cart_sidebar</name>
  </action>
</reference>
<reference name="right">
 <action method="insert">
  <block>cart_sidebar</block>
 </action>
</reference>

If you use:

<reference name="right">
  <block type="checkout/cart_sidebar" name="cart_sidebar"   template="checkout/cart/sidebar.phtml" />
</reference>

I think this would unnecessary create a new instance of the block class when the layout is generated.

Marius
  • 197,939
  • 53
  • 422
  • 830
Marina Gociu
  • 1,261
  • 8
  • 16