Add a link to Magento's My Account Page Conditionally
I would like to create a link on the My Account page that only get displays under certain conditions.
Right now I have the link display all the time by adding the following entry to my layout XML file:
<customer_account>
<reference name="customer_account_navigation">
<action method="addLink" translate="label" module="nie"><name>nie</name><path>nie</path><label>NIE Admin</label></action>
</reference>
</customer_account>
I am assuming there is a way to code this so that it only displays under certain 开发者_开发百科circumstances.
The cart & checkout links already do something similar so their method can be copied.
- Create a block. It won't be displaying directly so can be descended from the boring
Mage_Core_Block_Abstract
. Give it a method where the conditional logic will go.
public function addNieLink() { if (($parentBlock = $this->getParentBlock()) && (CONDITION-GOES-HERE)) { $parentBlock->addLink($this->_('NIE Admin'), 'nie', $this->_('NIE Admin'), true, array(), 50, null, 'class="top-link-cart"'); // see Mage_Page_Block_Template_Links::addLink() } } protected function _prepareLayout() { // Add the special link automatically $this->addNieLink(); return parent::_prepareLayout(); }
Put your check in place of
CONDITION-GOES-HERE
.Add your block to the links block.
<customer_account> <reference name="customer_account_navigation"> <block type="yourmodule/link" name="yourmodule.link" /> </reference> </customer_account>
(Correct the block type here to your newly created link block)
The important bit is it calls getParentBlock()
to find out where the link is to go.
精彩评论