Forum Discussion

bhupen's avatar
bhupen
Advisor
10 years ago
Solved

Show Rank icon

Hi All,

 

I made a custom call for latest post but now I need to show rank icon infront of author name. Following is the snippet I have used for post:

<#assign messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE author.id='${user.id}' ORDER BY post_time DESC LIMIT 5"?url) />
<#assign ranking= restadmin("/users/id/${author.id}/ranking")> /* rest call for rank*/
     <#list messages.data.items as recent >
     <#if recent?has_content>
        <p><a href="${recent.view_href}">${recent.subject}</a></p>
        <p>${ranking.left_image}</p>
        </#if>
     </#list>

 

Following is the example for rank icon:

rank.PNG

Above code is working fine for post, only rank icon need to display.

 

 

 

  • VarunGrazittithanks for your assitence over this discussion also your suggestion helped me as well. Following is the snippet which works perfectly as per my requirement.

     

    <#assign messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE author.id='${user.id}' ORDER BY post_time DESC LIMIT 5"?url) />
         <#list messages.data.items as recent >
         <#assign ranking= restadmin("/users/id/${recent.author.id}/ranking/display/left_image/url").value >
         <#if recent?has_content>
            <p><a href="${recent.view_href}">${recent.subject}</a></p>
            <p><img src="${ranking}" /> ${recent.author.login}</p>
            </#if>
         </#list>

    Note: Iam just putting it here for other help.

16 Replies

  • VarunGrazittithanks for your assitence over this discussion also your suggestion helped me as well. Following is the snippet which works perfectly as per my requirement.

     

    <#assign messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE author.id='${user.id}' ORDER BY post_time DESC LIMIT 5"?url) />
         <#list messages.data.items as recent >
         <#assign ranking= restadmin("/users/id/${recent.author.id}/ranking/display/left_image/url").value >
         <#if recent?has_content>
            <p><a href="${recent.view_href}">${recent.subject}</a></p>
            <p><img src="${ranking}" /> ${recent.author.login}</p>
            </#if>
         </#list>

    Note: Iam just putting it here for other help.

  • And you unmarked my post as solution and marked yours as the answer :D

    That's not fair. Thanks anyways.
  • bhupen's avatar
    bhupen
    Advisor
    10 years ago

    VarunGrazitti  the answer you shared was preety close to my request but when I compiled it then it was just fetching same icon for all users. After some edition I corrected it and marked mine solution because I don't want some one else will see the error in code.

     

    As I appreciated your help already. big thanks to you :)

  • simantel's avatar
    simantel
    Guide
    9 years ago

    VarunGrazitti, I feel like this post of yours is getting me really close to my answer. I'm making a custom component that will display each author's role beneath the stock Author component on each post. I've got the below code. It's grabbing my id to display the role rather than each author's. I need it to look at the authors rather than myself.

     

    <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
    ${role.name}
    </#list>

     

    Much appreciated!

  • VarunGrazitti's avatar
    VarunGrazitti
    Boss
    9 years ago
    simantel - This is because you are using ${user.id} in the API call, which is picking the ID of user in context, i.e. you. You need to pass the ID of the author instead.
  • simantel's avatar
    simantel
    Guide
    9 years ago

    Thanks for the response. I'm aware of this, but I don't know how to dynamically get the ID of the author. I want it to look at the context of message it is posted next to, or the stock Author component above it, with the username, rank, avatar, etc.