Velocity API available in Templates
General
Query result
TEXT
| The variable To learn more about result formatting, refer to Writing your own PocketQuery Templates and Writing your own PocketQuery Converters. Example Result passed from Converter
CODE
Template
HTML
Result
CODE
|
Query Parameters
TEXT
| Allows you to access the parameter values passed to your Query. If your Query statement makes use of wildcards, you can also find their values in this Map. Example Query Statement
CODE
Template
CODE
Result
CODE
|
Template insertion by Template ID
CODE
templateId: string | Renders another Template inside the caller Template. It requires a Template ID, which is a unique identifier of the template you want to parse (you can obtain it in the Template administration). You can call Warning: For each Query execution, Example Template 1 (main)
HTML
Template 2 (called)
CODE
Result
TEXT
|
Template insertion by Template name
TEXT
templateName: string | Renders another Template inside the caller Template. It requires a Template name, which can change over time. Please, use this method only in the case you are sure the name won’t change. Otherwise, use Warning: For each Query execution, Example Template 1 (main)
HTML
Template 2 (called)
HTML
Result
TEXT
|
Macro execution
TEXT
queryId: string | Executes another Query (including its Converter and Template) and returns the rendered result (as a Velocity template code). If you are looking to just get the raw result of another Query, use It requires 1 parameter: queryId, which is the ID of the Query to be executed (it can be obtained in the Query administration). The second argument is required in the case where the executed Query contains parameters. In that case, these parameters must be provided. Example
HTML
|
Query execution
TEXT
queryId: string | Executes another Query and returns the result (without applying Converter or Template). This allows you to work with the result of another Query within your Template. If you are looking to directly render another Query, use It requires 1 parameter: queryId, which is the ID of the Query to be executed (it can be obtained in the Query administration). The second argument is required in the case where the executed Query contains parameters. In that case, these parameters must be provided. Example
HTML
|
Locale (localization)
CODE
languageKey: string | Returns a ‘Locale’ (an object containing localization details) based on required country and language. This object is required for some other helpers to adjust their results to your location and language. It requires 1 parameter: language key. If you want to be more specific (suitable for english-speaking countries), you can also optionally provide country key parameter. The languageKey parameter refers to language identifier according to RFC-4646/4647. Example
HTML
Result
TEXT
|
Random UUID
CODE
| Generates a random UUID String that can be used to create a unique identifier within a Template. |
Date/Time Formatting
Format date and time
TEXT
timezone: string | Formats a date (as Unix Timestamp) into a human-readable format. It accepts 2 parameters: timestamp, date format, and optionally timezone. Example
HTML
Result
CODE
|
Parse date and time
TEXT
timezone: string | Converts a string representation of a date into a Unix Timestamp. It requires 2 parameters: string representation of date, date format, and optionally timezone. The date parameter is a date in string format. Example
HTML
Result
TEXT
|
Localized calendar
CODE
locale: localization | Returns a new localized java.util.calendar instance. It requires 2 parameters: localization and timezone. The locale parameter is a Locale object described above. Example
HTML
Result
TEXT
|
Text and Currency Formatting
Currency formatter
TEXT
locale: localization | Formats a number as a currency. It requires 2 parameters: localization and amount. The locale parameter is a Locale object described above. Example
HTML
Result
TEXT
|
Markdown formatter
CODE
markdownText: string | Formats Markdown text into HTML. 1 parameter is required: the Markdown text to be formatted. Example
HTML
Result (user sees rendered markup)
HTML
|
Collection Operations
New List
TEXT
items: enumeration (optional) | Creates a new list of items. It accepts an enumeration of list items. The number of items is not limited. On the returned list, you can call standard Java lists methods. Example
HTML
Result
TEXT
|
New list of unique items (Set)
TEXT
items: enumeration (optional) | Creates a new set of items. A set is a special type of list, containing only unique items. It accepts an enumeration of list items. The number of items is not limited. On the returned set, you can call standard Java lists methods. Example
HTML
Result
TEXT
|
New Map
TEXT
| Creates an empty map. A map is a collection of key:value attributes (such as a JSON object) called entries. You can use it to create custom objects in the Velocity template. On the created map, you can call standard Java methods. Example
HTML
Result
CODE
|
Object to flat list
CODE
object: object | Creates a List out of any Object, flattening nested objects inside. The Default Template uses this function to make a list out of the result. This allows the result to always be displayed as a table, no matter how complex it is. Example
HTML
Result
TEXT
|
Object flattening
CODE
object: object | Flattens an object. Nested object's parameters are appended to the parent object’s keys. Example
HTML
Result
TEXT
|
Make list items unique
CODE
list: list | Converts a collection (list/set/array) to a set (a list containing unique items only). Example
HTML
Result
CODE
|
Sort list
CODE
list: list | Sorts the provided list so its items are in an ascending oder. There are two ways to sort the list. You can either use the default comparator (for non-structured items). If the list contains structures (objects/maps), you can sort them using some particular parameter. Example
HTML
Result
TEXT
|
Reverse list
CODE
list: list | Reverses the order of items in the provided list. Example
HTML
Result
TEXT
|
Java Utils
PocketQuery provides some standard Java Utils. You can use them as standard Java objects and call their methods to format and convert your query results. Note that these utils are not available under the $PQ or $PocketQuery namespace, but under the global namespace..
Date (java.util)
CODE
| Returns a new java.util.Date instance. You can call Example
HTML
Result
TEXT
|
Number tool (org.apache.velocity.tools.generic)
CODE
| Returns a new org.apache.velocity.tools.generic.NumberTool instance. The default currency formatting is euro. Navigate to Currency formatting to see other formatting options. Example
HTML
Result
TEXT
|
Math tool (org.apache.velocity.tools.generic)
CODE
| Returns a new org.apache.velocity.tools.generic.MathTool instance. This instance can be use for basic mathematical operations, such as finding the average or maximum of some numbers. Example
HTML
Result
TEXT
|
Link tool (org.apache.velocity.tools.generic)
CODE
| Returns a new org.apache.velocity.tools.generic.LinkTool instance. This tool helps you to build URLs. Example
HTML
Result
CODE
|
Escape tool (org.apache.velocity.tools.generic)
CODE
| Returns a new org.apache.velocity.tools.generic.EscapeTool instance. This tool helps render tags and code snippets correctly. Example
HTML
Result
CODE
|
Calendar (java.util)
CODE
| Returns a new default java.util.calendar instance. The localization of the instance is default (CET). If you want to adjust the instance to your location, please, navigate to Localized calendar helper. Example
HTML
Result
TEXT
|