Forum Discussion

dustin's avatar
dustin
Expert
9 years ago

How do I get message id from Post Page?

On the Post Page, I would like to display a message based on the topic's age.   To do this, I first need to retrieve the ID of the topic message that is being replied to. The following didn't yield...
  • dustin's avatar
    9 years ago

    Because the message context object is not available on the post page, I found that you need to resort to other methods.

     

    The solution I implmented was to parse the request url with freemarker to grab both the board ID and message ID.  

     

    Here is the freemarker code...

      <#assign boardKey = "board-id">
      <#assign messageKey = "message-id">
    
      <#assign urlString = http.request.url>
      <#assign strCount = 0>
      <#list urlString?split("/") as subStr>
        <#if messagePos?? && strCount == messagePos>
          <#assign messageID = subStr>
        </#if>
        <#if boardPos?? && strCount == boardPos>
          <#assign boardID = subStr>
        </#if>
    
        <#assign strCount = strCount + 1>
    
        <#if subStr == boardKey>
          <#assign boardPos = strCount>
        </#if>
        <#if subStr == messageKey>
          <#assign messagePos = strCount>
        </#if>
    
      </#list>
    
      <#if boardID??>
          <div>Board ID: ${boardID}</div>
      </#if>
      <#if messageID??>
          <div>Message ID: ${messageID}</div>
      </#if>