Forum Discussion

PerBonomi's avatar
12 years ago
Solved

How do I get the most recent comments?

Using the example code at the bottom of my post (got it from the Lithosphere TKB) I can get the most recently kudoed messages, but I'm looking to list the most recent comments in our Idea Exchange.

 

I've tried all the combinations I can think of in the api call and I can't seem to get any data returned, apart from the example code.

 

I've changed

<#assign kudoedMessages = restadmin('/kudos/messages/leaderboard?max_age=one_week').messages />

 to all of these, with no luck:

 

<#assign kudoedMessages = restadmin('boards/id/ideaexchange/replies/').messages />

<#assign kudoedMessages = restadmin('boards/id/ideaexchange/replies/') />

<#assign kudoedMessages = restadmin('boards/id/ideaexchange').messages />

<#assign kudoedMessages = restadmin('boards/id/ideaexchange/').replies />

 

 

<!-- Create a macro that generates the list of recently kudoed messages in the community. We are using the same REST calls and      display logic used in the first application cache example -->

<#macro kudoedListDisplayM>
     <#assign kudoedMessages = restadmin('/kudos/messages/leaderboard?max_age=one_week').messages />
     <#assign kudoedList = [ ] />
     <#list kudoedMessages.message as m>
          <#assign authorUri = '/users/login/' + m.author.login />
          <#assign messageAuthor = restadmin(authorUri).user />
          <#assign authorAvatar = restadmin(authorUri + '/profiles/avatar').image />
          <#assign curr = { "message":m, "author":messageAuthor, "avatar":authorAvatar } />
          <#assign kudoedList = kudoedList + [ curr ] />
     </#list>

<p>Top kudoed messages:</p>
<p><ul>
     <#list kudoedList as k>
          <li>
          <p>${k.message.subject} </br>
                  <img src="${k.avatar.url}" />&nbsp;&nbsp;By: ${k.author.login}
          </p>
          </li>
       </#list>
     </ul>
</#macro>

 

<#assign kudoedListDisplay= appcache.get("kudoedListDisplay", "") />

<#if kudoedListDisplay != "">
<!-- kudoedListDisplay was NOT null, using cached value -->
<#else>

     <!-- kudoedListDisplay was null, populating list now using the macro created above-->
     <#assign kudoedListDisplay><@kudoedListDisplayM /></#assign>
     <#assign kudoedListDisplay = appcache.put("kudoedListDisplay", kudoedListDisplay) />
</#if>

<!-- Display the list -->

${kudoedListDisplay}

 

What am I doing wrong?

  • PaoloT's avatar
    PaoloT
    12 years ago

    Hi PerBonomi 

     

    you need to access it using the standard freemarker syntax for accessing XML attributes

     

    The below example will print the view_href attribute that is contained within the message object returned by the messages/id/XX call

     

    <#assign msg = rest("messages/id/12345?restapi.response_style=view").message>
    ${msg.@view_href}
    

     

    You can find the documentation here

     

    Cheers, 

9 Replies

  • PerBonomi's avatar
    PerBonomi
    Boss
    12 years ago

    Yes! that worked, thanks.

     

    Now, how do I go about getting the message url? I'd like to build an actual <a href>

  • PerBonomi's avatar
    PerBonomi
    Boss
    12 years ago

    Thanks nathan . I know that trick, but how do I pass the parameter into the freemarker code? :)

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    12 years ago

    PerBonomi , you can just append it to your call in the rest / restadmin freemarker function

     

    <#assign messages = rest("/boards/id/Lithium_Ideas/replies/recent?restapi.response_style=view").messages />

     

  • PerBonomi's avatar
    PerBonomi
    Boss
    12 years ago

    Done that too :)

     

    But how do I then read the href attrivute for use in the rest of the function? I don't know how to do that.

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    12 years ago

    Hi PerBonomi 

     

    you need to access it using the standard freemarker syntax for accessing XML attributes

     

    The below example will print the view_href attribute that is contained within the message object returned by the messages/id/XX call

     

    <#assign msg = rest("messages/id/12345?restapi.response_style=view").message>
    ${msg.@view_href}
    

     

    You can find the documentation here

     

    Cheers, 

  • PerBonomi's avatar
    PerBonomi
    Boss
    12 years ago

    Awesome! Exactly what I needed.

     

    Thanks so much for your patience and all the help, again :)

  • HaidongG's avatar
    HaidongG
    Lithium Alumni (Retired)
    11 years ago

    as just 2 cents :=)

     

    we need not to add "api.response_style=view" to any rest() or restadm() calls, as the backend will automatically add them.