0

I have added a custom cms-page 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.

Cms-page > Design > Layout Update XML

     <referenceContainer name="sidebar.main">
        <block class="Magento\Framework\View\Element\Template" name="customer_account_navigation_block" template="Magento_Theme::html/collapsible.phtml" before="-">
            <arguments>
                <argument name="block_title" translate="true" xsi:type="string">Account Dashboard</argument>
                <argument name="block_css" xsi:type="string">block-collapsible-nav</argument>
            </arguments>
            <block class="Magento\Framework\View\Element\Html\Links" name="customer_account_navigation" before="-">
                <arguments>
                    <argument name="css_class" xsi:type="string">nav items</argument>
                </arguments>
                <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-subscription-form">
                    <arguments>
                        <argument name="path" xsi:type="string">manage-subscription</argument>
                        <argument name="label" xsi:type="string">Email Subscription</argument>
                        <argument name="position" xsi:type="string">20</argument>
                    </arguments>
                </block>
            </block>
        </block>
    </referenceContainer>

Cms-page url:http://domain.com/manage-subscription/

0

I'm wondering if this does not quite work because this is a cms page and its possibly not matching absolutely. The Module Controller Action normally needs to match. In this case it's a CMS page so the page i think has the following absolute path: cms/page/view/page_id/1 where 1 is your page id so you could try changing path to below:

 <argument name="path" xsi:type="string">cms/page/view/page_id/1</argument>

This is a bit of a guess and would maybe debugging with the file that matches the links and sets them as active.

If this does not work you could debug by temporarily modifying vendor/magento/framework/view/element/html/link/current.php

This couuld be debugged by adding below code to isCurrent() function at around line 82 before return:

echo "CURRENT:" . $this->getCurrent() . "PATH:" . $this->getUrl($this->getPath()) . " MCA: " . $this->getUrl($this->getMca());

Or by doing similar in get MCA to work out why it isn't being matched. If you look at the code you should see what is going on and why the MCA does not match the path and what the MCA needs to be set to for it to match and the exact path that is needed to be used.

OR

I normally create a controller rather than a CMS page for additional pages in customer area and the links set as active fine there so could be worth setting up like that.

OR

You could also cheat a bit and do something like the following to workaround issue.

var url = window.location.pathname+window.location.search;
var els = document.querySelectorAll("a[href='" + url + "']");
$(els).addClass("current");

This would set any active links to have a class.

| improve this answer | |
  • Thanks for reply <argument name="path" xsi:type="string">cms/page/view/page_id/1</argument> not working. – Nitesh Sep 5 '17 at 9:45
  • I have fixed this by making some changes in current.php, will post answer later. – Nitesh Sep 5 '17 at 9:45
  • Nice one yeah would be good to know what was happening. – harri Sep 5 '17 at 9:46
  • I need to know, How should I override vendor/magento/framework/view/element/html/link/current.php file – Nitesh Sep 5 '17 at 10:14

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.