I need to add a custom tab at bottom of left menu on my account page 'link 1' and add a corresponding template file so that I can display my custom forms and dynamic custom content for that user.
I have tried the following:
This one doesn't works:
http://www.emiprotechnologies.com/technical_notes/magento-technical-notes-60/post/add-custom-tab-on-customer-account-section-in-magento-2-317
This one works but the links are not having template files:
https://magento.stackexchange.com/a/100096/39707
On customer page:
You can see my blog is displaying
After you click on 'My Blog': It takes to 404
Following is the complete module code:
Namespace/Support/view/frontend/layout/customer_account.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-suppport-ticket-link" after="-">
<arguments>
<argument name="path" xsi:type="string">support/customer/index</argument>
<argument name="label" xsi:type="string">Support Ticket</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Namespace/Support/view/frontend/layout/support_customer_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
<head>
<title>Support Ticket</title>
<css src="Namespace_Support::css/styles.css"/>
</head>
<body>
<referenceContainer name="content">
<block class="Namespace\Support\Block\TicketList" name="ticketViewList" template="Namespace_Support::list.phtml" />
</referenceContainer>
</body>
</page>
Namespace/Support/view/frontend/templates/list.phtml
<?php echo 'hello' ;?>
Namespace/Support/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Namespace_Support" setup_version="1.0.0">
<sequence>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>
Namespace/Support/Controller/Customer/index.php
<?php
namespace Namespace\Support\Controller\Customer;
use Magento\Framework\App\Action;
use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\Controller\ResultFactory;
class Index extends \Namespace\Support\Controller\Index
{
/**
* Show customer tickets
*
* @return \Magento\Framework\View\Result\Page
* @throws NotFoundException
*/
public function execute()
{
/** @var \Magento\Framework\View\Result\Page resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
return $resultPage;
}
}
Namespace/Support/Block/TicketList/index.php
<?php
namespace Namespace\Support\Block\TicketList;
class TicketList extends \Magento\Framework\View\Element\Template {
public function __construct(\Magento\Catalog\Block\Product\Context $context, array $data = []) {
parent::__construct($context, $data);
}
protected function _prepareLayout()
{
return parent::_prepareLayout();
}
}
Namespace/Support/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Namespace_Support',
__DIR__
);
Please guide me to achieve my task.
Best Answer
You are missing
routes.xml
file in your module. You need to createroutes.xml
file with below codeapp/code/Namespace/Support/etc/frontend/routes.xml
You should also correct you block like this - Remove
TicketList
from block namespace