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; ?>