Skip to main content
Skip table of contents

Templates

Templates are a type of PocketQuery Entity that defines how the result of a Query should be presented. They are snippets of Velocity Templating Language (VTL) and render your result data into HTML.

Velocity is a powerful language that allows you interact with your data in sophisticated ways, using directives like:

  • #if($condition) ... #else ... #end

  • #foreach($item in $list) ... #end

  • #set($variable = "value")

Velocity can also interact with APIs that are passed into their context, for example the PocketQuery Velocity API. We highly recommend reading the VTL reference and our Templating Tutorial if you want to learn how to effectively use Templates.

If you want to see a short example of how Templates can be used, have a look at this part of our Getting Started guide.

Default Template

If you don’t specify a Template yourself, PocketQuery will use this Template to render your query result into HTML. This is also the code that will be inserted into your editor if you hit the “Insert Example Code” button.

CODE
#set($tableRows = $PQ.toList($result))
#set($tableHeaders = $tableRows.get(0).keySet())
<table class="aui aui-table-sortable">
  <thead>
    <tr>
      #foreach ($header in $tableHeaders)
        <th>$!header</th>
      #end
    </tr>
  </thead>
  <tbody>
    #foreach ($row in $tableRows)
      <tr>
        #foreach ($column in $row)
          <td>$!column</td>
        #end
      </tr>
    #end
  </tbody>
</table>

If you are interested in resource limits related to Templates, check out this article. Also, notice that the <table> element has a class aui-table-sortable. With this class present, the table will be sortable by its columns.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.