Showing the user name in a template


5 Commentaires

  • Tal Admon

    Hi Diego,

    You can do this with a bit of javascript: see example below.

    The script: note that I set an empty span with the id "user_name". Then, I populate it according to the value of HelpCenter object.

    I also set "stranger!" when this value is null (in case of anonymous user), and an exclamation mark after the name.

    Let me know if you have any questions or if this does not work out for you.

    <div class="knowledge-base">
    <h1>{{}}</h1><h3>Hello, <span id="user_name"></span></h3>
    jQuery(document).ready(function(){var uname; if ({uname = "stranger!"} else {uname ="!"};jQuery('#user_name').html(uname);});


  • Diego Rod

    Thanks Taf, but why if I try to use {{}} directly to print the username in the homepage template I get:

    Unable to preview 'Home page' due to invalid reference: {{}}

    Or can I use this object only in javascript? Also where can I read more about these rules? I couldn't find anywhere that I have to put "HelpCenter" before for it to work.


  • Tal Admon

    Hi Diego,

    Not all objects are available in all template pages.

    In the case of the Home page, the User object is not available.

    Compare, for example the list of available properties of the Home page to the User Profile page:

    You will see the user object in the last row of the Available Properties table.

    So, for the homepage (or any other page) you will need to use the HelpCenter javascipt object which although I can't find about it in the official documentation it is referred to by many Zendesk users in the community.




  • Diego Rod

    Ah thanks, it makes more sense now!

    I was just grabbing the username from the user menu in the top left, but yeah the HelpCenter object seems like a more elegant solution.

    Thanks again!

  • Jessie Schutz
    Zendesk Customer Care

    Good to see you back, Tal!

    @diego, let us know if you need anything else! :)


Cette publication n’accepte pas de commentaire.

Réalisé par Zendesk