<![CDATA[Magento Help]]> http://magentist.com/magento_help/ Mon, 21 May 2012 23:08:47 +0000 Zend_Feed http://blogs.law.harvard.edu/tech/rss <![CDATA[Move Elements In Magento Templates]]> http://magentist.com/magento_help/move-elements-in-magento-templates/ Magento templates is usually fairly simple. A quick drag-and-drop of a small PHP script within a PHTML file is usually all you need.

But what if the layout you want to achieve would require you to move that PHP script to a different PHTML file? This may be fine on occassion, but you may often find that this will fail to output your content.

As an example, let's say you want to move your topLinks bar (the My Account, My Wishlist, My Cart, etc links) from the header.phtml file to the page layout files (1column.phtml, 2columns-left.phtml, etc). The php code you're looking for in header.phtml will look like this:

<?php echo $this->getChildHtml('topLinks') ?>
This cannot be directly transferred to the layout files because the PHP is requesting ChildHtml, and topLinks is a child of header.phtml, not the layout files. The solution? Reformat the PHP! Instead of using getChildHtml, use getLayout()->getBlock. This format should work in virtually any PHTML file in your Magento templates. The new code for our example would look like this:

<?php echo $this->getLayout()->getBlock('top.links')->toHtml()?>
Notice that the identifier has changed from "topLinks" to "top.links" The new identifier is the block's name, whereas the old identifier used the block's alias. This information was gathered from /app/design/frontend/default/template-name/layout/page.xml on this line:

<block type="page/template_links" name="top.links" as="topLinks"/>
]]>
Fri, 30 Jul 2010 18:50:40 +0000