Forum Discussion

frardouin's avatar
7 years ago

How to display avatar and login name of the current logged user in a custom document

Hi, I'm new to lithium and I'm try to get my head around something. I'm trying to understand how to query the info of the current user and display it in a freemarker custom component (it's for a custom top menu). I need the first name, last name, login name and avatar. But it's more how to build the query to get the user of the current session. Thanks a lot.

  • Payal's avatar
    Payal
    7 years ago

    Hi frardouin,

    You can use the folllowing v2 query to get the current logged user info:

     

     

    <#assign userInfo = rest("2.0", "/search?q=" + "Select * from users where id = '${user.id}'"?url).data.items />
    
    <#list userInfo as getInfo>
    <span>${getInfo.first_name}</span>
    <span>${getInfo.last_name}</span>
    <span>${getInfo.login}</span>
    <span>${getInfo.avatar.profile}</span>
    </#list>

     Let me know if it works for you.

     

    Thanks,

  • Does this make sense?

     

    <!-- display the avatar of current logged user -->
    <#assign avatar_url = rest("users/id/" + user.id + "/profiles/avatar?restapi.response_format=json").image.url![]/>
    <img src="${avatar_url}" alt="user-avatar">
    
    <!-- display the login name -->
    <a href="/t5/user/viewprofilepage/user-id/${user.id}">${user.login}</a>
    • Payal's avatar
      Payal
      Director

      Hi frardouin,

      You can use the folllowing v2 query to get the current logged user info:

       

       

      <#assign userInfo = rest("2.0", "/search?q=" + "Select * from users where id = '${user.id}'"?url).data.items />
      
      <#list userInfo as getInfo>
      <span>${getInfo.first_name}</span>
      <span>${getInfo.last_name}</span>
      <span>${getInfo.login}</span>
      <span>${getInfo.avatar.profile}</span>
      </#list>

       Let me know if it works for you.

       

      Thanks,