Created
September 2, 2011 13:54
-
-
Save astorm/1188644 to your computer and use it in GitHub Desktop.
Moving a Magento Block Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<layout> | |
<catalog_category_default> | |
<!-- block gets added --> | |
<reference name="content"> | |
<block type="core/text" name="are_you_sure"></block> | |
</reference> | |
</catalog_category_default> | |
<catalog_category_default> | |
<!-- later, a different handle gets a reference and sets block state --> | |
<reference name="are_you_sure"> | |
<action method="setText"><text>Hello World</text></action> | |
</reference> | |
</catalog_category_default> | |
<catalog_category_default> | |
<!-- we want to move a block, so we unset where it is --> | |
<reference name="content"> | |
<action method="unsetChild"><child>are_you_sure</child></action> | |
</reference> | |
</catalog_category_default> | |
<catalog_category_default> | |
<!-- WRONG WAY: we re-add the block, but we've lost state --> | |
<reference name="right"> | |
<block type="core/text" name="are_you_sure"/> | |
</reference> | |
</catalog_category_default> | |
<catalog_category_default> | |
<!-- Instead, use the insert method. This method accepts both a block object | |
OR a string. If you pass it a string, it gets a refernce to the block by that | |
name. The block, although unset, still exists on the layout object, which is why | |
this works --> | |
<reference name="right"> | |
<action method="insert"><block>are_you_sure</block></action> | |
</reference> | |
<!-- | |
if (is_string($block)) { | |
$block = $this->getLayout()->getBlock($block); | |
} | |
--> | |
</catalog_category_default> | |
</layout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment