Forum Discussion

Claudius's avatar
13 years ago

TKB hot articles custom component (code inside)

Thanks to quite some help here on the Developer Forums (thanks again to the Lithium h4x0rs) in the past two weeks I created this nice little custom component that shows you a configurable ( number_of_articles parameter in the first line) number for popular TKB articles in the Knowledge Base associated with the currently shown board. It helps surfacing the great knowledge in TKBs in a "Sticky post" like manner. 

 

The presentation looks like the board topic view and if you add it to the Forum Page layout it looks like this:

 

TKB_preview.PNG

 

Here's the code: 

<#assign number_of_articles = 2>
<#assign hot_article_kudo_treshold = 10>

<#assign tkb_present = rest("/boards/id/${coreNode.id}/tkb/realized").value?eval />
<#if tkb_present>
<#assign articlecount = rest("/boards/id/${coreNode.id}%40tkb/messages/count").value?number />
<#if (articlecount > 0)>
	<table class="lia-list-wide">
	<thead>
		<tr>
		<th scope="col" class="messageStatusIconColumn lia-data-cell-tertiary lia-data-cell-icon t-first"/>
		<th scope="col" class="threadSubjectColumn lia-data-cell-primary lia-data-cell-text"> Knowledge Base Article </th>
		<th scope="col" class="viewCountColumn lia-data-cell-secondary lia-data-cell-integer"> Views </th>
		<th scope="col" class="kudosCountColumn lia-data-cell-secondary lia-data-cell-integer"> Kudos </th>
		<th scope="col" class="latestPostDateColumn lia-data-cell-secondary lia-data-cell-date"> Last Updated </th>
		</tr>
	</thead>
	<tbody>
	<#assign popular = rest("/boards/id/${coreNode.id}%40tkb/threads/popular?page_size=${number_of_articles}&restapi.response_style=view").threads.thread />
	<#list popular.messages.topic as message>
		<tr>
			<td colspan="1" rowspan="1" class="messageStatusIconColumn lia-data-cell-tertiary lia-data-cell-icon">
				<img class="MessageStatusIcon" title="Knowledge Base Article" alt="Read full article after the link" src="<#if (message.kudos.count?number > hot_article_kudo_treshold)>${skin.images.icon_tkb_thread_hot.url}<#else>${skin.images.icon_tkb_thread.url}</#if>"/>
			</td>
			<td><a href="${message.@view_href}">${message.subject}</a></td>
			<td>${message.views.count}</td>
			<td>${message.kudos.count}</td>
			<td>
				<#if message.last_edit_time.@view_friendly_date = "">
					${message.last_edit_time.@view_date}
				<#else>
					${message.last_edit_time.@view_friendly_date}
				</#if>
			</td>
		</tr>
	</#list>
	</tbody>
	</table>
	<p style="text-align: right">
	<a href="${community.urls.tapestryPrefix}/${coreNode.title}-Knowledge-Base/tkb-p/${coreNode.id}@tkb">More Knowledge Base articles …</a>
	</p>
</#if>
</#if>

2 Replies

  • Nice work, Claudius.  On the TKB URL side, one thing that might work better than trying to manually construct the URL (in case of a long title) is to use REST:

     

    <#assign tkb_url = rest("/boards/id/${coreNode.id}/tkb/get").board.@view_href />
    ...
    <a href="${tkb_url}">More Knowledge Base articles …</a>

     

  • Claudius's avatar
    Claudius
    Boss
    13 years ago
    Nice addition. Thanks.

    I try to keep REST calls to a minimum for performance reasons and because of the fact that REST calls are sometimes capped in contracts ;)