8

I want to add a dynamic label in customer dashboard (label name set dynamically )

<?xml version="1.0"?>

<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"/>
    <body>   
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-custom-product" ifconfig="mconnect_csproduct/cs_customer/display_on_dashboard">
                <arguments>
                    <argument name="path" xsi:type="string">vender/customer/products/</argument>
                    <argument name="label" xsi:type="string" translate="true">dynamic label add</argument>                      
                </arguments>
            </block>
        </referenceBlock>
    </body> 
</page>

enter image description here

Prince Patel
  • 22,708
  • 10
  • 97
  • 119
Nikhil Vaghela
  • 1,341
  • 9
  • 19

1 Answers1

9

You can use helper to get dynamic label. Add helper in <argument/> and chnage xsi:type="string" to xsi:type="helper"

<argument name="label" xsi:type="helper" helper="Vendor\Module\Helper\Data::getLabel"></argument>                     

In your helper, you can get dynamic label like this

<?php

namespace Vendor\Module\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    public function getLabel()
    {
        //Your logic here

        $label = "Dynamic Label based on your logic";

        return $label;
    }
} 

I use this same way to change logo dynamically. Refer this answer for more info: https://magento.stackexchange.com/a/176309/35758

If you want to change the whole link HTML of navigation refer this answer: https://magento.stackexchange.com/a/190842/35758

Prince Patel
  • 22,708
  • 10
  • 97
  • 119