Creating Dynamic Links in ‘My Account’ or in the ‘Toplinks’ Menu in Magento

May 28, 2014427
Creating Dynamic Links in ‘My Account’ or in the ‘Toplinks’ Menu in Magento

I am sure many of you have once faced the necessity of creating links in ‘My account’ or ‘Toplinks’ menu. It is quite simple to implement – just add the following code into xml:

After that all you need is to create an appropriate controller (mymodule/myblock/index), a template for the content (mymodule/myblock.phtml), a block (mymodule/myblock) and to define them in the xml:

The only drawback is that the link is a static one, so it does not depend on any conditions or events. The easiest way to make it dynamic (dependent on events and conditions) is to use Magento events together with handles.

First off, let’s change the default handle <customer_account> to the custom handle <random_name_handle> in the aforementioned xml:

Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

Next we assign an observer to the event <controller_action_layout_load_before>:

Creating an appropriate observer and a method for it:

The key point – $observer->getEvent()->getLayout()->getUpdate()->addHandle(‘random_name_handle’) – adds the handle <random_name_handle> and thereby adds the link if the condition is true.

Partner With Us Looking for a partner that will help you to grow your business? We are the right company to develop your webstore. Feel free to get in touch with us. We will be happy to discuss your business opportunities and provide you with a Free Quote. Talk to Igor

1 comment

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *