Forum Discussion

dustin's avatar
dustin
Expert
9 years ago

Freemarker needed to display floated threads for a board

I'm using the following rest api call to retrieve the floated threads. However, I am unable to process the returned posts. 

 

 

			<#assign floated_messages = rest("/boards/id/${coreNode.id}/subscriptions/global/float/thread?page_size=10") >
			<#if floated_messages?size gt 0>
				<div class="floated_posts_list_body">
					<ul class="posts">
						<#list floated_messages as message>
							<li class="post">
								<div class="post_main">
									${message.subject}
								</div>
							</li>
						</#list>
					</ul>
				</div>
			<#else> 
				<div>There are no floated posts</div>
			</#if>

 

 I believe I am missing an object at the end of the rest call. For example...

 

 

<#assign floated_messages = rest("/boards/id/${coreNode.id}/subscriptions/global/float/thread?page_size=10").threads >

 

 

But that isn't working either.  Does anyone know what the answer is and where that documentation might be found?

  • dustin's avatar
    dustin
    9 years ago

     

    The code above works.  Here is some additional info for others...

     

    Documentation related to structuring the API call can be found here: Subscriptions API

     

    One item that tripped me up was that you need to make sure that when you float posts during testin, you choose the option "Float Topic for All Users".  The call to get these posts is... 

    <#assign floated_messages = rest("/boards/id/${coreNode.id}/subscriptions/global/float/thread").subscriptions.subscription.target.messages.topic >

    There is also the option to float a post for yourself ("Float this Topic to the Top").  To display those floated posts, the call is...

    <#assign floated_user_messages = rest("/boards/id/${coreNode.id}/subscriptions/users/self/float/thread").subscriptions.subscription.target.messages.topic >

    If you would like to merge those, the code to do that is...

    	<#list floated_user_messages as user_message>
    		<#assign is_duplicate = false>
    		<#list floated_messages as existing_message>
    			<#if existing_message.id == user_message.id>
    				<#assign is_duplicate = true />
    			</#if>
    		</#list>
    		<#if is_duplicate == false>
    			<#assign floated_messages = floated_messages + [user_message] />
    		</#if>
    	</#list>

    All put together, you can display your floated posts with this code...

    <#if coreNode.nodeType == "board"> 
    	<#if page_number == 0>
    		<#assign floated_messages = rest("/boards/id/${coreNode.id}/subscriptions/global/float/thread").subscriptions.subscription.target.messages.topic >
    		<#assign floated_user_messages = rest("/boards/id/${coreNode.id}/subscriptions/users/self/float/thread").subscriptions.subscription.target.messages.topic >
    		<#list floated_user_messages as user_message>
    			<#assign is_duplicate = false>
    			<#list floated_messages as existing_message>
    				<#if existing_message.id == user_message.id>
    					<#assign is_duplicate = true />
    				</#if>
    			</#list>
    			<#if is_duplicate == false>
    				<#assign floated_messages = floated_messages + [user_message] />
    			</#if>
    		</#list>
    		
    		<#if floated_messages?size gt 0> 
    			<ul class="floated_posts"> 
    				<#list floated_messages as message> 
    				<li class="post"> 
    					<div class="post_main"> 
    						${message.subject} 
    					</div> 
    				</li> 
    				</#list> 
    			</ul> 
    			
    		<#else> 
    			<div>There are no floated posts</div> 
    		</#if> 
    	</#if> 
    </#if> 

     

     

  • Hi dustin,

     

    There was a problem in parsing. I have made some changes in your code. Please try it.

    <#assign floated_messages = rest("/boards/id/${coreNode.id}/subscriptions/global/float/thread?page_size=10").subscriptions.subscription >
    
    <#if floated_messages?size gt 0>
    	<div class="floated_posts_list_body">
    		<ul class="posts">
    			<#list floated_messages.target.messages.topic as message>
    				<li class="post">
    					<div class="post_main">
    						${message.subject}
    					</div>
    				</li>
    			</#list>
    		</ul>
    	</div>
    <#else> 
    	<div>There are no floated posts</div>
    </#if>

    Give a Kudo and Accept as Solution if my post answes your question.:smileyhappy:

     

    Thanks, 

    Vishwajeet

    • dustin's avatar
      dustin
      Expert

       

      The code above works.  Here is some additional info for others...

       

      Documentation related to structuring the API call can be found here: Subscriptions API

       

      One item that tripped me up was that you need to make sure that when you float posts during testin, you choose the option "Float Topic for All Users".  The call to get these posts is... 

      <#assign floated_messages = rest("/boards/id/${coreNode.id}/subscriptions/global/float/thread").subscriptions.subscription.target.messages.topic >

      There is also the option to float a post for yourself ("Float this Topic to the Top").  To display those floated posts, the call is...

      <#assign floated_user_messages = rest("/boards/id/${coreNode.id}/subscriptions/users/self/float/thread").subscriptions.subscription.target.messages.topic >

      If you would like to merge those, the code to do that is...

      	<#list floated_user_messages as user_message>
      		<#assign is_duplicate = false>
      		<#list floated_messages as existing_message>
      			<#if existing_message.id == user_message.id>
      				<#assign is_duplicate = true />
      			</#if>
      		</#list>
      		<#if is_duplicate == false>
      			<#assign floated_messages = floated_messages + [user_message] />
      		</#if>
      	</#list>

      All put together, you can display your floated posts with this code...

      <#if coreNode.nodeType == "board"> 
      	<#if page_number == 0>
      		<#assign floated_messages = rest("/boards/id/${coreNode.id}/subscriptions/global/float/thread").subscriptions.subscription.target.messages.topic >
      		<#assign floated_user_messages = rest("/boards/id/${coreNode.id}/subscriptions/users/self/float/thread").subscriptions.subscription.target.messages.topic >
      		<#list floated_user_messages as user_message>
      			<#assign is_duplicate = false>
      			<#list floated_messages as existing_message>
      				<#if existing_message.id == user_message.id>
      					<#assign is_duplicate = true />
      				</#if>
      			</#list>
      			<#if is_duplicate == false>
      				<#assign floated_messages = floated_messages + [user_message] />
      			</#if>
      		</#list>
      		
      		<#if floated_messages?size gt 0> 
      			<ul class="floated_posts"> 
      				<#list floated_messages as message> 
      				<li class="post"> 
      					<div class="post_main"> 
      						${message.subject} 
      					</div> 
      				</li> 
      				</#list> 
      			</ul> 
      			
      		<#else> 
      			<div>There are no floated posts</div> 
      		</#if> 
      	</#if> 
      </#if>