Forum Discussion

jaread83's avatar
jaread83
Champion
9 years ago

Custom component to show who Kudoed a post

I am building a custom component that will list all users who clicked the kudo button on every post. All was going well until I needed to cut off the amount to display and show a message to say to that the user needs to click the link to view the rest. Basically, this is what I am trying to acheive...

  • get the post message unique ID
  • assign a cutoff number (10 in my case)
  • get the rest to give me a list of users who clicked kudos button on this message using page_size with my cutoff number
  • assign a variable to give the total number of kudos for my message
  • once all the above has been set, show a 'XX users kudoed this post'
  • Then loop through the user list and display the usernames
  • If the amount of kudos exceeds my cut off, display a message 'Click here to view who else kudoed this post' (this is where the issue occurs).

So the problem is that when comparing the cutoff number with the kudoscount variable, it says I can't compare these two numbers. I am not sure exactly how to fix this... I am sure it would be pretty simple though! Here is my code:

 

<#assign messageId = env.context.message.uniqueId />
<#if messageId?? && messageId gt 0>
<#assign cutoff = 10 />
<#assign users = rest("/messages/id/${messageId}/kudos/givers?page_size=${cutoff}").users />
<#assign kudosCount = rest("/messages/id/${messageId}/kudos/count").value />
<#if users??>
${kudosCount} users kudoed this post<br>
<#list users.user as kudosGiver>
${kudosGiver.login}<br>
</#list>
<#if kudosCount gte cutoff >
Click here to view who else kudoed this post.
</#if>
</#if>
</#if>

 

Any help would be greatly appreciated.

Thanks!

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)

    Hi jaread83

     

    have you tried ensuring that the value returned by REST is treated as a number by freemarker?

     

    <#assign kudosCount = rest("/messages/id/${messageId}/kudos/count").value?number?c />

    Find out more on the docs pages

     

    Hope it helps!

  • I figured out!

    <#if kudosCount?number gte cutoff?number >

    bit of a facepalm moment.