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

1
  • hello nikhil, i have same issue. Are you find any solution? Aug 8, 2017 at 9:59

1 Answer 1

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.