Forum Discussion

yurikleban's avatar
9 years ago

Exposing a rank

Hey Folks,

 

Sorry for the newbie q but I was just wondering if anyone has successfully exposed a user ranking in the front-end to the user (based on who the user is, not a hardcoded rank). I was trying to run a simple component that has 'rank - ${rank.name} ' but it is evaluating as null/ missing.  Any thoughts?

 

-Y

  • yurikleban - You must be trying the component in the logged out state, i.e. if you run this API, you'll get rank name as N/A

     

    /restapi/vc/users/id/-1/ranking/name

     

    Try this code and it should work fine.

     

    <#attempt>
             <#if !user.anonymous> <!-- Only triggers when the user is logged in -->
                  <#assign rank = restadmin("/users/id/${user.id}/ranking/name").value>
                    Rank - ${rank} 
             </#if>
    <#recover>
               <!-- Something went wrong -->
    </#attempt>
  • yurikleban - You must be trying the component in the logged out state, i.e. if you run this API, you'll get rank name as N/A

     

    /restapi/vc/users/id/-1/ranking/name

     

    Try this code and it should work fine.

     

    <#attempt>
             <#if !user.anonymous> <!-- Only triggers when the user is logged in -->
                  <#assign rank = restadmin("/users/id/${user.id}/ranking/name").value>
                    Rank - ${rank} 
             </#if>
    <#recover>
               <!-- Something went wrong -->
    </#attempt>
    • yurikleban's avatar
      yurikleban
      Mentor
      That did the trick, thank you so much! Interesting that an API call must be made, but some reason I thought it was just a variable you can call upon.

      Thanks so much Varun!!!