Forum Discussion

dustin's avatar
dustin
Expert
10 years ago

How to retrieve page number in freemarker?

On the community page, I have created a custom component that lists all of the messages for that board.  I am using the default pagination extension and while it allows me to click to any page, the same results show on each page.  So I need to incorporate the page offset into the SQLi.

 

I see the page number in the url...

ex: http://community.lithium.com/t5/Technology/bd-p/technology/page/2

 

Is there a way to access this page number with FreeMarker from the url or a context object?

 

This is what I'm starting with...

 

<#assign result_count = 25 />
<#assign pagination_offset = 0 />
// if page_number exists
<#assign pagination_offset =page_number * result_count />
// end if

<#assign recent_messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE board.id IN ('${coreNode.id}') AND depth=0 ORDER BY post_time DESC LIMIT ${result_count} OFFSET ${pagination_offset}"?url).data.items />

  • I worked out my own answer...

     

    Here is the code that worked for me.  The webuisupport.path.parameters.name.get("page") is the key.

     

    				<#assign result_count = 25 />
    				<#if webuisupport.path.parameters.name.get("page") ??> 
    					<#assign page_number = webuisupport.path.parameters.name.get("page")?number /> 
    					<#assign page_number = page_number - 1 />
    				<#else> 
    					<#assign page_number = 0 />
    				</#if>
    				<#assign pagination_offset = page_number * result_count />
    
    				<#assign recent_messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE board.id IN ('${coreNode.id}')  AND depth=0 ORDER BY post_time DESC LIMIT ${result_count} OFFSET ${pagination_offset}"?url).data.items />

1 Reply

  • I worked out my own answer...

     

    Here is the code that worked for me.  The webuisupport.path.parameters.name.get("page") is the key.

     

    				<#assign result_count = 25 />
    				<#if webuisupport.path.parameters.name.get("page") ??> 
    					<#assign page_number = webuisupport.path.parameters.name.get("page")?number /> 
    					<#assign page_number = page_number - 1 />
    				<#else> 
    					<#assign page_number = 0 />
    				</#if>
    				<#assign pagination_offset = page_number * result_count />
    
    				<#assign recent_messages = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE board.id IN ('${coreNode.id}')  AND depth=0 ORDER BY post_time DESC LIMIT ${result_count} OFFSET ${pagination_offset}"?url).data.items />