Forum Discussion

bhupen's avatar
bhupen
Advisor
10 years ago

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.

  • bhupen - Below is the updated code

     

    <#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/display/left_image/url").value > /* rest call for rank*/
         <#list messages.data.items as recent >
         <#if recent?has_content>
            <p><a href="${recent.view_href}">${recent.subject}</a></p>
         <img src="${ranking}"/>
            </#if>
         </#list>

     

    I hope this helps.

    • bhupen's avatar
      bhupen
      Advisor

      VarunGrazittithanks for this. But its giving me null pointer exception. Following is the exception:null.PNG

       

      If iam putting check for null pointer{author.id} records stopped showing up.

       

      • It should be user.id instead of author.id in the following line.

        <#assign ranking= restadmin("/users/id/${user.id}/ranking/display/left_image/url").value >
  • 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

        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 :)