1

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

enter image description here

After you click on 'My Blog': It takes to 404

enter image description here

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.

12
  • Possible duplicate of magento.stackexchange.com/questions/112178/… Jan 17, 2018 at 9:44
  • Is custom link showing or not? Jan 17, 2018 at 9:46
  • @Magento2Learner: no its not. For first link nothing is working and for second only custom links are being displayed on myaccount page but it do not have any phtml template. Jan 17, 2018 at 9:56
  • It would be better that you share some of code so exact problem can be identified. Jan 17, 2018 at 10:19
  • 1
    @WasiqShahrukh as mentioned by Suresh Chikani you need to add routes.xml file. Jan 17, 2018 at 11:18

1 Answer 1

4

You are missing routes.xml file in your module. You need to create routes.xml file with below code

app/code/Namespace/Support/etc/frontend/routes.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="support" frontName="support">
            <module name="Namespace_Support" />
        </route>
    </router>
</config>

You should also correct you block like this - Remove TicketList from block namespace

<?php

namespace Namespace\Support\Block;


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();
    }

}
6
  • It is now giving error page. This is the report file Jan 17, 2018 at 12:12
  • First enable developer mode and check. Jan 17, 2018 at 12:14
  • In Developer mode, I got following exception: '2 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid block type: Namespace\Support\Block\TicketList Exception #1 (ReflectionException): Class Namespace\Support\Block\TicketList does not exist' Jan 17, 2018 at 12:37
  • 1
    Check my updated answer, You have to correct your block namespace and path. Jan 17, 2018 at 12:50
  • Hi @SureshChikani How to add same links as dropdown under one link in magento2 Dec 5, 2018 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.