Forum Discussion
So I think I answered my own question. Using your example, I changed the REST API call from a featured fetch to one that gets solutions, then once I matched on the thread I looped through the solutions (since there can be more that one) and gathered the IDs into a sequence, then output them into the meta tag like so:
<#if page.context.thread??> <#list rest("/boards/id/${coreNode.id}/solutions/recent?page_size=999").threads.thread as thread> <#if thread.messages.topic.id?number == page.context.thread.topicMessage.uniqueId> <#assign seqSolutions = []> <#list thread.solutions.solution as solution> <#assign seqSolutions = seqSolutions + solution.id> </#list> <meta name="solutions" content="${seqSolutions?join(",")}" /> <#break /> </#if> </#list> </#if>
Seems to work well, but if there is a better or more efficient way I would love to know.
Cheers,
Robert
That seems like a good approach. The only optimization I might recommend is to use a LiQL query instead so you can limit the amount of data that needs to be retrieved and processed -- something like this should do the trick:
<#if page.context.thread??>
<#assign query = "SELECT id FROM messages WHERE topic.id = '" + page.context.thread.topicMessage.uniqueId + "' AND is_solution = true" />
<#assign resp = rest("2.0", "/search?q=" + query?url) />
<#assign seqSolutions = []>
<#list resp.data.items as solution>
<#assign seqSolutions = seqSolutions + [solution.id]>
</#list>
<#if (seqSolutions?size gt 0)>
<meta name="solutions" content="${seqSolutions?join(",")}" />
</#if>
</#if>
(I would of course also reccomend that you put in proper error handling for your rest v2 calls, as we write about in the Error handling in FreeMarker with Community API v2 article)
-Doug
- DougS10 years agoKhoros Oracle
Going along with the last reply I made, the custom component mentioned in the topic message could be re-written using LiQL as follows:
<#if page.context.thread??> <#assign resp = rest("2.0", "/messages/" + page.context.thread.topicMessage.uniqueId + "?fields=conversation(featured)") /> <#if resp.data.conversation.featured> <meta name="featuredtopic" content="yes" /> </#if> </#if>
Related Content
- 4 years ago
- 9 months ago
- 14 years ago