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
  • 6
    Change the path from <argument name="path" xsi:type="string">support/customer/index</argument> to <argument name="path" xsi:type="string">support/customer</argument> Commented Apr 22, 2016 at 13:26
  • Let me know if it helps Commented Apr 22, 2016 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
    Commented Apr 22, 2016 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
    Commented Apr 22, 2016 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 Commented May 16, 2017 at 6:50

2 Answers 2

24

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.

7
  • If I have another action name instead of Index , then doesnot not called....
    – Manish
    Commented Nov 7, 2016 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. Commented Nov 10, 2016 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. Commented May 5, 2017 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
    Commented Jul 11, 2017 at 12:35
  • @YagneshPonkiya What about cms page? Commented Sep 4, 2017 at 9:59
4

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 and acknowledge you have read our privacy policy.

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