Forum Discussion

phoneboy's avatar
phoneboy
Director
4 months ago

How do I get the article ID in Freemarker in a TkbArticle?

This is Community Classic.

I'm trying to write a component to display something from a hidden field (canonical_url) while on the page of a TkbArticle.
It doesn't appear that either page.context.message.id or env.context.message.id work in anything Tkb related.

What other options do I have to retrieve this information in the context of the page itself?

2 Replies

  • phoneboy 
    We can use the below context object to get the article ID inside the TkbMessage quilt on the TkbArticlePage.
    ${env.context.message.uniqueId}

    For article ID on TkbArticlePage.
    ${page.context.thread.topicMessage.uniqueId}

    For message/comment ID on TkbArticlePage.
    ${page.context.message.uniqueId}

  • To get the article ID in a TkbArticle on Community Classic, try the following:

    1. Direct Access: freemarker${article.id} or ${tkbArticle.id}
    2. Model or Context: freemarker${model.id} or ${page.context.article.id}
    3. Custom Field (if available): freemarker${tkbArticle.customFields.canonical_url}
    4. Debugging: Dump all available variables: freemarker<#list .data_model?keys as key> ${key}: ${.data_model[key]}<br> </#list>

    These should help you locate the article ID.