1

Can anyone tell me how do I bold this highlighted text "Product name" from notification message.

Note: Message comes from .csv file. Image blow

  • which magento 2 version you are working ? – fmsthird Apr 15 at 6:50
  • I am using magento 2.2.5 ee – Muhammad Anas Apr 15 at 6:54
0

I have the exact same business requirement. It is not possible to add html tags in translation csv file but you may enter specific unique character in csv file for specific message. So I add jQuery code to do this work, I know it is not the best practice but it worked for me. As there is no answer yet against this question so I share what I did.

First you have to add unique specific characters (strong) and (/strong) in your theme translation csv file and string variable between those specific characters like

You added %1 to your shopping cart.","You added (strong)%1(/strong) to your shopping cart.

Then Add this jQuery code in your JS file

jQuery(document).ajaxStop(function() {
    var notificationMessage = jQuery.trim(jQuery("#maincontent.page-main.container > .messages .messages").find( "div:eq(1)" ).text());
    if(notificationMessage != ""){
        setTimeout(function () {
            var strong = jQuery('#maincontent.page-main.container > .messages .messages:contains("(strong)")').html();
            if(typeof strong !== 'undefined'){
                strong = strong .replace("(strong)", "<strong>");
                strong = jQuery.trim(strong.replace("(/strong)", "</strong>"));
            }
            jQuery('#maincontent.page-main.container > .messages .messages:contains("(strong)")').html(strong);
        }, 200);
    }
});

I hope this will help

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.