From version 1.1 >
edited by Fawad Ali
on 2019/08/19 14:00
To version < 2.1
edited by Fawad Ali
on 2019/08/19 14:20
Change comment: There is no comment for this version

Summary

Details

ExtensionCode.ExtensionClass[0]
Description
... ... @@ -23,7 +23,7 @@
23 23  #set ($fullKey = "#getFullKey($testValues 'value')")
24 24  
25 25  ## Now get the value at the full key
26 -$testValues.get($fullKey)
26 +$testValues.get($fullKey.trim())
27 27  
28 28  {{/velocity}}
29 29  {{/code}}
cogGet full key from a HashMap which has multiple keys with unknown suffixes such as 'textarea_en', 'textarea__' in Solr response
Developed by

Fawad Ali

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

{{velocity}}

## Macro for getting full key from a short key (useful for keys with multiple unknown suffixes as in solr response)
#macro (getFullKey $valuesMap $shortKey)
 #foreach ($key in $valuesMap.keySet())
   ## Check each key if it starts with the given value
   #if ($key.startsWith($shortKey))
     #set ($fullKey = $key)
     #break
   #end
 #end
  $fullKey
#end

#set ($testValues = {
 'value_en': 'Hello',
 'value__': 'Hello',
 'value_test': 'Hello'
})

## This will get the first full key that starts with 'value'
#set ($fullKey = "#getFullKey($testValues 'value')")

## Now get the value at the full key
$testValues.get($fullKey)

{{/velocity}}
{{velocity}}

## Macro for getting full key from a short key (useful for keys with multiple unknown suffixes as in solr response)
#macro (getFullKey $valuesMap $shortKey)
 #foreach ($key in $valuesMap.keySet())
   ## Check each key if it starts with the given value
   #if ($key.startsWith($shortKey))
     #set ($fullKey = $key)
     #break
   #end
 #end
  $fullKey
#end

#set ($testValues = {
 'value_en': 'Hello',
 'value__': 'Hello',
 'value_test': 'Hello'
})

## This will get the first full key that starts with 'value'
#set ($fullKey = "#getFullKey($testValues 'value')")

## Now get the value at the full key
$testValues.get($fullKey.trim())

{{/velocity}}

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Get Connected