I have a template which looks like this :
#set($list = [])
#foreach($x in $_global.get('agg'))
$list.add($x.data.listingID)
#end
{
"queueName": "TEST",
"hosts": "localhost",
"credentials": {
"username": "guest",
"password": "guest"
},
"payload" : {
"userId" : "$_event.get('id')",
"aggData" : $vch.toJSON($list)
}
}
On rendering against a sample payload I get something like this :
true
true
{ "queueName": "BRO-EM-MPNACC00CARTDEV1",
"hosts": "localhost",
"credentials": {
"username": "guest",
"password": "guest"
},
"payload" : {
"userId" : //id,
"aggData" : //something
}
}
How can I handle foreach returning 'true' ?
To suppress output of the return value of the
add()
method, you'll need to assign it to a velocity variable, something like:More details in this SO answer.