10

I am trying to add a custom link in customer account navigation. My custom link is showing in account navigation and working too, but it's not showing as active/current on click.

enter image description here

Below is the code I have:

/app/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>

/app/code/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;
    }
}

/app/code/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>
  • 5
    Change the path from <argument name="path" xsi:type="string">support/customer/index</argument> to <argument name="path" xsi:type="string">support/customer</argument> – Codrain Technolabs Pvt Ltd Apr 22 '16 at 13:26
  • Let me know if it helps – Codrain Technolabs Pvt Ltd Apr 22 '16 at 13:27
  • @YagneshPonkiya. Thank for your quick reply. Yes, it's working. Put your comment as an answer so that I can accept. – Shyam Apr 22 '16 at 13:50
  • @YagneshPonkiya. Also, can you please tell me what was the issue? Why did we need to change that? Thanks in advance. – Shyam Apr 22 '16 at 13:51
  • @Shyam, Have you completed this module? I am creating the same functionality in my M2 project. So, could you please guide me how I can create this functionality? Thanks – mageDev0688 May 16 '17 at 6:50
23

To get the things done, please change the path in your layout file like below.

<argument name="path" xsi:type="string">support/customer</argument>

Please note, i have removed action part from the path string.

For more information, why you need to do this please study below file.

Magento\Framework\View\Element\Html\Link\Current.php

Hope, this will help you.

  • If I have another action name instead of Index , then doesnot not called.... – Manish Nov 7 '16 at 8:09
  • if you have other action other than "index". you should use full path like "support/customer/abc". Also make sure your frontname and route id are same. – Codrain Technolabs Pvt Ltd Nov 10 '16 at 13:08
  • @YagneshPonkiya, I am facing same issue at the moment and I have put question here I have tried with the above code but I am getting 404 page issue. – mageDev0688 May 5 '17 at 12:43
  • @Yagnesh if I am on customer/account/ page then the menu has the class "current". However if I am on customer/account/edit page the "current" class is not present. Can you help? I want to have "current" class on the menu for internal pages as well. – Sejal Shah Jul 11 '17 at 12:35
  • @YagneshPonkiya What about cms page? – Nitesh Sep 4 '17 at 9:59
2

You can write in your custom layout

<referenceBlock name="customer-account-navigation-suppport-ticket-link">
                <arguments>
                    <argument name="current" xsi:type="boolean">true</argument>
                </arguments>
    </referenceBlock>

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.