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

Répondu

6 Commentaires

  • Trapta Singh
    Community Moderator

    Hi Groffer Anderson,

    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
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Hi Groffer Anderson,

    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

     

    2
  • Groffer Anderson

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

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Awesome :)

     

    0
  • Ashok Gangwar

    This link does not exist anymore.

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Hi @Ashok Gangwar,

    You can share your query. Sometimes it happens that old links don't open.

    0

Vous devez vous connecter pour laisser un commentaire.

Réalisé par Zendesk