Forum Discussion

Gursimrat's avatar
Gursimrat
Leader
11 years ago

Parent post issue

I am customizing the recent posts widget where in I have to show the latest reply with the parent post, but I am getting an issue with getting the parent post of the main topic (which ofcourse would be a null as it is the parent post itselt), how can I just show the main post in this case

 

I am getting the parent of the recent post by /messages/id/${posts.id}/parent but this causes exception when this is running for the original post as it does not find the parent for it.

    • Henrik's avatar
      Henrik
      Advisor

      Hi Gursimrat ,

       

      I have used "root" instead of "parent" in my case.

      Something like:

       

      <#assign reply_root = rest("/messages/id/${reply_id}/root").message />
      <#if reply_root.id != reply_id>
      The message is a reply to the topic whose id is ${reply_root.id}
      </#if>

       Cheers,

      Henrik

      • samudhraa's avatar
        samudhraa
        Expert

        Hi Gursimrat ,

         

        Check out this snippet of code.

        It checks if the message has parent ,if so assigns parent path to a variable.

        If the message is a parent by itself , it assigns the message path to the variable.

         

        <#assign response = rest("/posts/recent").messages/>
        <#list response.message as message>
             <#if (message.parent.@href?size>0)>
                <#assign parentMsgId= message.parent.@href />
             <#else>
                   <#assign isParent = message.parent.@null />
                    <#if isParent=="true">
                         <#assign parentMsgId = message.@href />
                   </#if>

               </#if>
        ${parentMsgId}
        <br/>
        </#list>

         

        Hope that helps. 

        Thanks,

        Sam