Pulling Content using RESTful ContentAPI

Description

This example shows how to pull content from an external dotCMS site using the ContentAPI and displays the results paginated.

Code

${esc.h}set(${esc.d}page=1)
${esc.h}set(${esc.d}limit=5)

${esc.h}if(${esc.d}request.getParameter("page"))
${esc.h}set(${esc.d}page=${esc.d}math.toInteger(${esc.d}request.getParameter("page")))
${esc.h}end

${esc.h}set(${esc.d}nextPage=${esc.d}math.add(${esc.d}page,1))
${esc.h}set(${esc.d}prevPage=${esc.d}math.sub(${esc.d}page,1))

${esc.h}set(${esc.d}offset=${esc.d}math.mul(${esc.d}page,${esc.d}limit))
${esc.h}set(${esc.d}offset=${esc.d}math.sub(${esc.d}offset,1))

${esc.h}set(${esc.d}myjson = ${esc.d}json.fetch("http://dotcms.com/api/content/render/false/query/+structureName:PressRelease/orderby/modDate%20desc/limit/${esc.d}limit/offset/${esc.d}offset"))

${esc.h}foreach(${esc.d}content in ${esc.d}myjson.contentlets)

<p><a href="http://www.dotcms.com/about/press-release/${esc.d}content.urlTitle">${esc.d}content.title</a>
<br/>${esc.d}content.teaser
</p>
${esc.h}end


${esc.h}if(${esc.d}prevPage>0)
<a href="?page=${esc.d}prevPage">Previous</a> | 
${esc.h}end
<a href="?page=${esc.d}nextPage">Next</a>