I don’t know why it is so difficult. If I understand THIS correctly, I must quickly fulfill my goals ... But without joy.
So - I'm building my first theme and still racking my brains over the layout ...
I work specifically on the Catalog Product View page, and I convert this page from the layout of the right column to the layout of the left column. I just want to move the blocks from right to left.
The standard .xml directory defines product_list_related :
</catalog_product_view> //... <reference name="right"> <block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/> </reference> </catalog_product_view>
In my local.xml, I'm just trying to move this block:
<layout> // bunch other page directives <catalog_product_view> <reference name="root"> <action method="setTemplate"><template>page/2columns-left.phtml</template></action> </reference> <reference name="right"> <action method="unsetChild"><name>catalog.product.related</name></action> </reference> <reference name="left"> <action method="insert"><blockName>catalog.product.related</blockName></action> // note that that "catalog.leftnav" gets inserted as expected <block type="catalog/layer_view" name="catalog.leftnav" after="-" template="catalog/layer/view.phtml"/> </reference> </catalog_product_view> </layout>
As noted, the catalog.leftnav insert works as expected, so I assume that everything else is configured correctly. The target block displays as expected if I leave the template and other directives unchanged, which tells me that the block should be displayed after it has been correctly deleted and inserted ...
It drives me crazy ... but what else is new with Magento.
Greetings -
B [] x
UPDATE
Since I just cannot get the local.xml override to work, I just go back to the modified catalog.xml . I'm a very smart guy ... it bothers me that I can't get this to work (and this purple sound just fails, no matter what happens), but I can't spend more time tricking this stupid problem.
Moving.
UPDATE, again.
Some time has passed, now, working in purple and finding out its complexity. Today I returned to this problem, since I need my local.xml to work correctly.
I really don't know that I was wrong, but this set of directives finally worked.
<reference name="right"> <action method="unsetChild"> <alias>catalog.product.related</alias> </action> </reference> <reference name="left"> <action method="insert"> <block>catalog.product.related</block> </action> </reference>
The key point that I will tell others about this:
Xml Layout directives call available methods in magento classes. In this case, the Page.xmls "Left" block is of type Mage_Core_Block_Text , which inherits from Mage_Core_Block_Abstract , which contains the unsetChild and insert methods.
from Mage_Core_Block_Abstract :
public function unsetChild($alias) { if (isset($this->_children[$alias])) { unset($this->_children[$alias]); } if (!empty($this->_sortedChildren)) { $key = array_search($alias, $this->_sortedChildren); if ($key !== false) { unset($this->_sortedChildren[$key]); } } return $this; }
and
/** * Insert child block * * @param Mage_Core_Block_Abstract|string $block * @param string $siblingName * @param boolean $after * @param string $alias * @return object $this */ public function insert($block, $siblingName = '', $after = false, $alias = '') { if (is_string($block)) { $block = $this->getLayout()->getBlock($block); } if (!$block) { /* * if we don't have block - don't throw exception because * block can simply removed using layout method remove */ //Mage::throwException(Mage::helper('core')->__('Invalid block name to set child %s: %s', $alias, $block)); return $this; } if ($block->getIsAnonymous()) { $this->setChild('', $block); $name = $block->getNameInLayout(); } elseif ('' != $alias) { $this->setChild($alias, $block); $name = $block->getNameInLayout(); } else { $name = $block->getNameInLayout(); $this->setChild($name, $block); } if ($siblingName === '') { if ($after) { array_push($this->_sortedChildren, $name); } else { array_unshift($this->_sortedChildren, $name); } } else { $key = array_search($siblingName, $this->_sortedChildren); if (false !== $key) { if ($after) { $key++; } array_splice($this->_sortedChildren, $key, 0, $name); } else { if ($after) { array_push($this->_sortedChildren, $name); } else { array_unshift($this->_sortedChildren, $name); } } $this->_sortInstructions[$name] = array($siblingName, (bool)$after, false !== $key); } return $this; }
The local xml parameters are important, not in the name (in particular), but in order, that is:
<reference name="left"> <action method="insert"> <block>catalog.product.related</block> <siblingName>catalog.leftnav</siblingName> <after>1</after> <alias>catalog_product_related</alias> </action> </reference>
This ultimately makes local.xml a really powerful way to manipulate the system, but if you are not familiar with it and the magento system, get ready for weeks or months of work to really think about it.
Greetings
Another update
I ran into a problem several times when the block that I want to move is deleted. This is a problem, since any block that has been removed from the layout is permanently disabled.
However, with Alan Storm it’s very convenient Unremove Plugin you can undo what was done:
<checkout_onepage_index> <x-unremove name="left" /> <reference name="right"> <action method="unsetChild"> <alias>checkout.progress.wrapper</alias> </action> </reference> <reference name="left"> <action method="insert"> <block>checkout.progress.wrapper</block> </action> </reference> </checkout_onepage_index>
He manages this feat by observing the layout object and creating a list of deleted blocks that can be referenced later.
Nice!