To add current class in Customer Account dashboard Custom Link

 Add the below code in module_index_index.xml under the body tag.

<referenceBlock name="customer-account-navigation-custom-index-index">
        <arguments>
            <argument name="is_highlighted" xsi:type="boolean">true</argument>
        </arguments>
      </referenceBlock>

customer-account-navigation-custom-index-index is a block name of in customer_account.xml

Example of

Please add the below code in module_index_index.xml under body tag

<referenceBlock name="customer-account-navigation-custom-index-index">
        <arguments>
            <argument name="is_highlighted" xsi:type="boolean">true</argument>
        </arguments>
      </referenceBlock>

customer-account-navigation-custom-index-index is a block name of in customer_account.xml

Example of  module_index_index.xml file :

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
    <head>
        <title>Title</title>
    <body>
      <referenceBlock name="customer-account-navigation-custom-index-index">
        <arguments>
            <argument name="is_highlighted" xsi:type="boolean">true</argument>
        </arguments>
      </referenceBlock> 
      <referenceBlock name="customer_account_navigation">
          <referenceContainer name="content">
            <block class="Namespace\Module\Block\Index\Index" name="name" template="template.phtml"></block>
        </referenceContainer>
    </referenceBlock>
    </body>
</page>
After run this command php bin/magento setup:upgrade && php bin/magento setup:static-content:deploy -f

This will add the current class and highlight it automatically when you are on that page.

Leave a comment

Your email address will not be published. Required fields are marked *