Customizing Magento Customer Account Dashboard
As a Magento developer, you may often need to extend or modify the customer account dashboard. Perhaps you want to add new links for your customers to access special features of your store. In this article, I’ll guide you through the process of adding additional links to the Magento my account page.
Understanding the Customer Account Layout
The Magento customer account dashboard is primarily defined by two files:
app/design/frontend/<vendor>/<theme>/template/page/html/toplinks.phtmlapp/design/frontend/<vendor>/<theme>/layout/customer.xml
These files are responsible for rendering the top navigation links and defining the layout structure, respectively.
Adding New Links in toplinks.phtml
Open your theme’s toplinks.phtml file located at:
app/design/frontend/<vendor>/<theme>/template/page/html/toplinks.phtml
This is where you can add new links to the top navigation bar. Find the following block of code inside the <div class="links"> tag:
<div class="links">
<?php if ($this->helper('customer')->isLoggedIn()): ?>
<ul>
<li><span><?php echo $this->translate('Welcome, %name!', array('%name%' => $this->escapeHtml($this->customerHelper->getCustomer()->getName()))); ?></span></li>
<?php if ($this->getIsNeedShowSwitchAccountLink()): ?>
<li><a href="<?php echo $this->helper('customer')->getCreateAccountUrl() ?>"><?php echo $this->translate('Create an Account'); ?></a></li>
<?php endif; ?>
</ul>
<?php else: ?>
<div class="top-link-welcome">
<?php if ($this->getIsNeedShowCreateAccountLink()): ?>
<span><?php echo $this->translate('Welcome, Guest!') ?>
<a href="<?php echo $this->helper('customer')->getCreateAccountUrl() ?>" id="top-link-create-account"><?php echo $this->translate('Create an Account'); ?></a>
</span>
<?php else: ?>
<?php if ($this->helper('customer')->isAllowedToSwitchAccount()): ?>
<div class="button-switcher">
<a href="#" onclick="switchAccount('<?php echo $this->jsQuoteEntity($this->getUrl('customer/account_login')) ?>')" id="top-link-signin"><?php echo $this->translate('Sign In'); ?></a>
<span id="top-link-acc-switch">or</span>
<a href="<?php echo $this->helper('customer')->getCreateAccountUrl() ?>" id="top-link-create-account"><?php echo $this->translate('Create an Account'); ?></a>
</div>
<?php else: ?>
<span><?php echo $this->translate('Welcome, Guest!') ?>
<a href="<?php echo $this->helper('customer')->getLoginUrl() ?>" id="top-link-signin"><?php echo $this->translate('Sign In'); ?></a>
</span>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
Within the <ul> tags, you can add your new links using the following format:
<li><a href="<?php echo $this->getUrl('catalog/product/list') ?>"><?php echo $this->translate('Special Products'); ?></a></li>
Replace catalog/product/list with the route to the page where you want to direct the customer, and update Special Products with your link text.
Defining New Blocks in customer.xml
For more complex layouts or to define new blocks on the my account page, you can modify the following file:
app/design/frontend/<vendor>/<theme>/layout/customer.xml
Within the <default> node under <customer_account_index_index>, you can define a new block like this:
<block type="core/text_list" name="my.new.block" as="newBlock">
<action method="addLink" translate="label" module="page">
<label>My Custom Link</label>
<url helper="catalog/product/list"/>
</action>
</block>
This example defines a new block called newBlock and adds a link to it. Replace the url attribute with your desired route.
Conclusion
In this post, we covered how to add new links in Magento’s customer account dashboard. By editing the toplinks.phtml file, you can easily extend the top navigation bar for logged-in customers. For more complex layouts, you can modify the customer.xml layout file to define additional blocks.
Remember to always create a child theme and make your changes there to avoid overwriting updates from Magento or the base theme. For further reference on Magento theme development best practices, I recommend checking out our comprehensive guide at Laravel Company’s blog.
Don’t hesitate to reach out if you have any other questions about Magento development!