Forum Discussion

Mdavis399's avatar
Mdavis399
Contributor
4 years ago

Help with Editing a Component with Freemarker

Hi everyone,

I need help using the Freemarker code in order to edit one of my custom components.

Following the steps outlined in this tutorial,  I was able to write a component that retrieved and displayed the latest Blog article from a specific board. In my case the board_id was "puget-soundblog-board," and the code for my component looks like this:

<h2>Most Recent Blog Article</h2>
<#assign recent= rest("/boards/id/puget-soundblog-board/topics/recent?page_size=1").messages />
<a href="${recent.message.@view_href}">${recent.message.subject}</a>
<span class=“post-time”>
<#if recent.message.post_time.@view_friendly_date[0]??>
${recent.message.post_time.@view_friendly_date}
<#else>
${recent.message.post_time.@view_date}
</#if>
</span>

 

My question is, what do I need to do/change in order for the component to retrieve more blogs? Say I wanted to display 3 to 5 of the latest blogs from that same board, how can I do that? Additionally, is there a way to edit the component so that it retrieves blogs from whichever node it is housed in? Right now, it is pulling blogs from one specific board, but it would be ideal if I could use this component elsewhere in my community and have it automatically grab blogs from that second location instead of the original.

My ultimate goal with this is to have a component that I can place on a Group Hub landing page and have it populate the space with some of the most recent blogs posted in said Group Hub.

Any help is much appreciated! Thanks!

  • Hi Mdavis399 , you should be able to increase the number of posts displaying by increasing page_size=1 to page_size=3 or page_size=5

    To make the component dynamic and dependent on the board it's loading in, you can used coreNode.id to retrieve the blog id and load it as a variable, so:

    <#assign blogId = coreNode.id />

    and then:

    <#assign recent= rest("/boards/id/${blogId}/topics/recent?page_size=5").messages />

    I think that's right anyway 😊

  • Hi Mdavis399 , you should be able to increase the number of posts displaying by increasing page_size=1 to page_size=3 or page_size=5

    To make the component dynamic and dependent on the board it's loading in, you can used coreNode.id to retrieve the blog id and load it as a variable, so:

    <#assign blogId = coreNode.id />

    and then:

    <#assign recent= rest("/boards/id/${blogId}/topics/recent?page_size=5").messages />

    I think that's right anyway 😊