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

May 28, 2014 1759 Updated: September 26, 2019 15:39
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:

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


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.

magento custom development

Magento Custom Development

Take your online store to the next level with BelVG Magento Custom Development

Visit the page
Andrey Dubina
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

1 comment

Post a new comment