I have added the custom tab on the customer dashboard using the code:

<?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">
        <referenceBlock name="customer_account_navigation">
            <!-- <update handle="customer_account_navigation"/> -->

            <block class="Magento\Framework\View\Element\Html\Link\Current" name="demo-link">
                    <argument name="path" xsi:type="string">addprofile/index</argument>
                    <argument name="label" xsi:type="string">Demo Link</argument>

Now what I want is I want to show this tab to only a particular customer group. As the link was added through the XML file and when I checked the navigation.phtml it is rendering all the links using

<?php echo $block->getChildHtml();?>

So I wasn't able to add some condition there.

can anyone help?



1 Answer 1


I hope you get an idea from this, I have not tested. I have tried like remove that block programatically when customer group id is not match with our expectation, .

protected $_customersession;
public function __construct(\Magento\Customer\Model\Session $customersession)

public function yourMethod()
        $cgid=$customerSession->getCustomer()->getGroupId();  // get Customer Group Id
            $layout = $this->getLayout();
            $block = $layout->getBlock('demo-link'); // block name
            $layout->unsetElement('demo-link'); //remove block
  • Hi Bilal thanks for the answer but i am confused on implementing it.where should i add this code as the tab is added from layout. Also i didn't find the template for customer_account Commented Oct 24, 2016 at 4:58
  • in layout you can't find customer group for add tab, as I know the only possibilities to check from controller so you should need to apply this logic in your custom controller execute method. Commented Oct 24, 2016 at 5:04
  • How is that going to work coz i want to hide this tab for particular customer group but controller of my module is only executed when someone click this link Commented Oct 24, 2016 at 5:10
  • oh you right! in your case you need to override and try this logic in app/code/Magento/Customer/Controller/Account/Index.php Commented Oct 24, 2016 at 5:12
  • Hi bilal i tried it above code. The line with $layout = $this->getLayout(); is giving the error of unable to handle the request. can you suggest what could possibly go wrong. Commented Nov 17, 2016 at 12:39

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.