How can I check the user type for the logged in user on Help center Template code?

Répondu

4 Commentaires

  • Trapta
    Community Moderator

    Hi Raghav Mishra,

    Zendesk does not provide any variable on the template level to give the user role other than user_profile_page.hbs.

    However, you can use JS to achieve this by using window.HelpCenter.user.role

    It will give you the current role of the user and on the basis of that, you can show/hide the option.

    Let me know if this helps you.

    Thanks

    1
  • Ifra Saqlain
    Community Moderator

    Hi Raghav,

    You can also use the method below:

     you can check the user role using JS:

    You can add the user role on the scrip.js file and show/hide any content.

    // Show div html based on role
    if (HelpCenter.user.role=="anonymous"){
    $("div.anonymous").show();
    }

    if (HelpCenter.user.role=="end_user"){
    $("div.end_user").show();
    }

    if (HelpCenter.user.role=="agent"){
    $("div.agent").show();
    }

    if (HelpCenter.user.role=="manager"){
    $("div.manager").show();
    }

     

    You can add the content in the header.hbs file and hide that on the user basis like:

    On header.hbs file

    <div class="wrapper"> Content will show only on manager role</div>


    On script.js file

    $(document).ready(function(){
    if (HelpCenter.user.role=="manager"){
    $('.wrapper').hide();
    }
    })

     

    the full process that how to use the user role script code so go through the article below:

    https://support.zendesk.com/hc/en-us/community/posts/360039994333-How-to-hide-an-article-from-an-anonymous-user-

     

    Thanks

     

    1
  • Raghav Mishra

    Thanks Trapta & Ifra Saqlain
    These solutions worked like a charm. 

    0
  • Ifra Saqlain
    Community Moderator

    Awesome :)

     

    0

Vous devez vous connecter pour laisser un commentaire.

Réalisé par Zendesk