PerBonomi
12 years agoBoss
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}" /> 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?
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,