Hi i have created account navigation link, and i have two customer groups in magento admin panel, and i only want to display that links to specific group rather than displaying all the time.
here is my xml code for displaying links.
<?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-new-product-link" after="-">
<arguments>
<argument name="label" xsi:type="string">Some link</argument>
<argument name="path" xsi:type="string">customer/somelink/index</argument>
</arguments>
</block>
</referenceBlock>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-new-some-link" after="-">
<arguments>
<argument name="label" xsi:type="string">new link here</argument>
<argument name="path" xsi:type="string">customer/somelinkhere/index</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
please suggest a way for this.
Best Answer
Check this for more info: blog.mageprince.com
1) Define Your block class
{vendor}\{Module}\Block\Customer\Link
in navigation link2) Now create Link.php at
app/code/{Vendor}/{Module}/Block/Customer/Link.php
Here you make the dynamic link as per your logic. Here I check current customer groupId and return HTML of link if customer group = 1 otherwise return null.
This same way you can make your second link dynamic.
1) Define helper class
{vendor}\{Module}\Helper\Data
in navigation link2) Now create Data.php at
app/code/{Vendor}/{Module}/Helper/Data.php
Note :
In Magento 2.1.x remove
var/generation
andflush cache
.In Magento 2.2.x remove
generated/code
andgenerated/metadata
andflush cache
.