I need to add new tab in my custom module to frontend(my account)
-> this may be addLink or customer_account_navigation (its depend on the requirment) viewwedding_couplewedding_couple/customer/view/ZZZZZZZZ
<wedding_couple_customer> –> controller path
 <update handle="customer_account"/>
 <reference name="my.account.wrapper">
 <block type="wedding_couple/customer" name="wedding_couple_newtab_newtab" template="customer/newtab/newtab.phtml"/>
 </reference>
</wedding_couple_customer>
 2 Answers 2
Ensure you have also declared your layout file in config.xml:
<?xml version="1.0"?>
<config>
 ...
 <frontend>
 ...
 <layout>
 <updates>
 <module>
 <file>module.xml</file>
 </module>
 </updates>
 </layout>
 ...
 </frontend>
 ...
</config>
and then add the following:
<?xml version="1.0"?>
<layout version="0.1.0">
 ...
 <customer_account>
 <reference name="customer_account_navigation">
 <action method="addLink">
 <name>unique_tab_name</name>
 <path>module/controller</path>
 <label>Your Tab Label</label>
 </action>
 </reference>
 </customer_account>
 ...
</layout>
Ensure you have declared your controller resource in you modules config.xml:
<?xml version="1.0"?>
<config>
 ...
 <frontend>
 ...
 <routers>
 <module> <!-- this matches the first part of the layout handle
 <use>standard</use>
 <args>
 <module>Namespace_Module</module>
 <frontName>module</frontName> <!-- this matches 'module' before the slash in the path node above -->
 </args>
 </module>
 </routers>
 ...
 </frontend>
 ...
</config>
Then in your controller action referenced by module/controller in the path node add the following to render the layout (but first redirect if the user is not logged in):
<?php
class Namespace_Module_ControllerController extends Mage_Core_Controller_Front_Action
{ 
 public function indexAction()
 {
 if (!Mage::getSingleton('customer/session')->isLoggedIn()):
 $this->_redirect('customer/account/login');
 return;
 endif;
 $this->loadLayout();
 $this->renderLayout();
 }
}
Then in your layout file declare the content you want to load when clicking the tab (which will result in a request to the Namespace_Module_ControllerController):
<?xml version="1.0"?>
<layout version="0.1.0">
 <module_controller_index> <!-- module here matches node directly beneath <routers> in config.xml -->
 <update handle="customer_account"/> <!-- include existing customer account layout -->
 <reference name="my.account.wrapper"> <!-- target parent block -->
 <block type="module/block" name="unique_layout_name" template="module/template.phtml"/>
 <block type="customer/account_dashboard" name="customer.account.link.back" template="customer/account/link/back.phtml" /> <!-- add a back link -->
 </reference>
 </module_controller_index>
</layout>
Now in your block class add the following, you'll probably want to be able to pull the customer object hence adding the getCustomer() method:
<?php
class Namespace_Module_Block_Block extends Mage_Core_Block_Template
{
 public function getCustomer()
 {
 $customer = Mage::getSingleton('customer/session')->getCustomer();
 if ($customer->getId()):
 return $customer;
 endif;
 return false;
 }
}
And finally in your template module/template.phtml output whatever you need to:
<div class="page-title">
 <h1><?php echo $this->__('My Tab') ?></h1>
</div>
<?php if ($customer = $this->getCustomer()): ?>
 <div>Hello <?php echo $customer->getName(); ?></div>
<?php else: ?>
 <div>No customer here</div>
<?php endif; ?>
 - 
 Great, could you mark the answer as accepted in that case?Jonathan Hussey– Jonathan Hussey2014年12月15日 15:56:33 +00:00Commented Dec 15, 2014 at 15:56
 
You can add by using following set of xml
<customer_account>
 <reference name="customer_account_navigation">
 <action method="addLink" translate="label" module="customer"><name>custom_menu</name><path>custommodule/controller</path><label>My Custom Menu</label></action>
 </reference>
</customer_account>
You will need to alter the name,path, label values accordingly.