@query

Queries for nodes and makes those nodes available to the template.

Parameters

parameter required description
type the type of node to query for (definition QName)
sort the field to sort on
sortDirection the direction to sort in (either 1 for ascending or -1 for descending)
limit the number of records to return
skip a position to skip ahead to in the record set
scope if "page", then only relatives related to the current page will be returned
as specifies the name of the resultsvariable (by default - rows)
field the name of a property to match against)
fieldRegex the match to run against the field)
fieldValue the fixed value to check against the field)
near geolocation coordinates to query around
locale the locale to use in retrieving content
cache whether to utilize fragment caching

Response

The result is an associative array of key/value pairs for each of your nodes. Each key is the resulting node ID and each value is the JSON for the node.

Examples

Example #1: Restaurant Names

Here is an example where we retrieve nodes of type custom:restaurant. We use this to build out a table. Each row of the table shows the restaurant's node ID and title.

{@query sort="title" skip="0" limit="5" type="custom:restaurant"}
   <table>
   {#rows}
      <tr>
         <td>{_doc}</td>
         <td>{title}</td>
      </tr>
   {/rows}
   </table>
{/query}

Example #2: Restaurant List with Thumbnail Images

Here is an example that lists restaurants and shows an thumbnail image for each:

{@query sort="title" skip="0" limit="5" type="custom:restaurant"}
   <table>
   {#rows}
      <tr>
         <td>
            {#attachments.default}
            <img src="{preview64}">
            {/#attachments.default}
         </td>
         <td>{title}</td>
      </tr>
   {/rows}
   </table>
{/query}

Example #3: Restaurants near Boston

Here is an example where we retrieve nodes of type custom:restaurant that are near a specific geographic location - that of Boston, Massachusetts.

Each row of the table shows the restaurant's node ID and title.

{@query sort="title" skip="0" limit="5" type="custom:restaurant" near="42.3584308,-71.0597732"}
   <table>
   {#rows}
      <tr>
         <td>{_doc}</td>
         <td>{title}</td>
      </tr>
   {/rows}
   </table>
{/query}

Example #4: Restaurant List (with Caching)

We can use the cache parameter to tell the tag to cache the resulting response fragment. Cached fragments are reused on subsequent page renders. As such, the first execution of this tag will result in an API query call. The generated HTML will be cached and subsequent requests will simply draw from cache.

As a result, your tag will execute more quickly as it avoids the overhead of going back over the wire to the Cloud CMS API. The cache will automatically be invalidated when any of the input parameters or nodes being rendered are touched on the API side.

{@query sort="title" skip="2" limit="7" type="custom:restaurant" cache="true"}
   <table>
   {#rows}
      <tr>
         <td>{_doc}</td>
         <td>{title}</td>
      </tr>
   {/rows}
   </table>
{/query}