Skip to main content
Skip table of contents

How to replace 4.x deprecated PocketQuery functions in Templates?

As mentioned in PocketQuery 4.x Upgrade Notes, PocketQuery now uses dynamic forms instead of static templates. Therefore, some functions you have been using in the previous version might be deprecated now. In this article, we provide examples that you can use to replace getValueFromMapEntry andgetParameterFromRequestOrMacro functions.

Example 1: getValueFromMapEntry

You can iterate a map/object using the following function:

CODE
#foreach($entry in $parameters.entrySet())
  <p>$entry.key - $entry.value</p>
#end

Where $entry.key returns the key and $entry.value returns the value. Considering $parameters to be the following object:

JAVA
{
  "catName": "Ingmar",
  "dogName": "Ingwer"
}

The result would be:

CODE
  <p>catName - Ingmar</p>
  <p>dogName - Ingwer</p>

If you want to obtain only a specific value, you can do it more efficiently. Instead of iterating the whole object, you can simply call the following function:

JAVA
$parameters.get("catName")

Which returns Ingmar 🐱.

Example 2: getParameterFromRequestOrMacro

This function can be replaced by $pocketQueryParameters. You can find more details in Velocity API Available In Templates. In PocketQuery 3.x, you might have been using:

CODE
#set ($reqParam = $PocketQuery.getParameterFromRequestOrMacro("param", $req, $queryParameters))

This can be easily substituted by:

CODE
#set ($reqParam = $pocketQueryParameters.get("param"))

Which does the same trick.

JavaScript errors detected

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

If this problem persists, please contact our support.