Velocity rendering ; problems with foreach returning true

526 views Asked by At

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' ?

1

There are 1 answers

0
Stephen Hartley On

To suppress output of the return value of the add() method, you'll need to assign it to a velocity variable, something like:

#set($ignore = $list.add($x.data.listingID))

More details in this SO answer.