4

I want to create a link dynamically in customer_block_account_navigation (link supposed to show up in the sidebar)

A static link isn't a problem, you can achieve that with a xml layout update:

<customer_account>
    <reference name="customer_account_navigation">
        <action method="addLink" translate="label" module="customer">
            <name>mymodulename</name>
            <path>mypath</path>
            <label>Label of the link</label>
        </action>
    </reference>
</customer_account>

The link goes to a custom form which supposed to show up only for certain customer. So I need to control the link (or layout update) via PHP in my own module. But I couldn't find any solution how to do that.

Can anyone help me?

Thank you so much.

  • see the template for customer_account_navigation block – Mohammad Faisal May 1 '14 at 4:43
  • Thank you! I ended up by overwriting the addLink function of the class _Block_Customer_Account_Navigation (in my own extension). In the new function I'm gonna filter the concerning link. – Stefan May 1 '14 at 14:43
11

You can add a block inside the customer_account_navigation and in that block, add the link to the parent block if your conditions are satisfied.

So in your layout goes this:

<customer_account>
    <reference name="customer_account_navigation">
        <block type="[module]/customer_link" as="[module]_customer_link" name="[module]_customer_link">
            <action method="addLinkToParentBlock" />
        </block>
    </reference>
</customer_account>

And your block class shoud look like this:

class [Namespace]_[Module]_Block_Customer_Link extends Mage_Core_Block_Abstract 
{
    public function addLinkToParentBlock() 
    {
        $parent = $this->getParentBlock();
        if ($parent) {
            if (your condition goes here) {
                $parent->addLink(
                    'Label goes here',
                    'Url goes here',
                    'title goes here',
                );

            }
        } 
    }
}

This way, your block will get instantiated. It will have no output, but the method addLinkToParentBlock will be called.

2

That really depends what you want with your dynamic link. You could do a few things:

  1. Rewrite Mage_Customer_Block_Account_Navigation and change the getLinks function to add your link where ever you need,
  2. Rewrite Mage_Customer_Block_Account_Navigation and change the addLink function to add your link with the information created dynamically,
  3. You could even listen to the event core_block_abstract_to_html_before check the block type and then change the links here,
1

Try this code for admin Navigation

<customer_account translate="label">
    <reference name="left">
        <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
        <action method="addLink" translate="label" module="customer"> <name>my_customadmin</name><path>mypath/mycustomadmin/</path><label>My Custom Navigation</label></action>
        </block>
    </reference>
</customer_account>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.