append for string variable in Apache Velocity Template Language
Asked Answered
G

1

5

I want to construct query string in the API Gateway mapping template. I have something like this

#foreach($entry in $entries)
  #set($count = $foreach.count)
  #set($entriesQueryString = "$!{entriesQueryString}Id=${count}&"
#end

The idea is to append new string as long as there are entries provided in the input.

Is my code valid? Any other ways to do append?

Glomerulonephritis answered 30/7, 2020 at 20:13 Comment(0)
P
6

According to this post and VTL user guide page, the way concatenation is done is just by "putting items together". From the VTL guide:

A common question that developers ask is How do I do String concatenation? Is there any analogue to the '+' operator in Java?. To do concatenation of references in VTL, you just have to 'put them together'. The context of where you want to put them together does matter, so we will illustrate with some examples. In the regular 'schmoo' of a template (when you are mixing it in with regular content) :

#set( $size = "Big" )
#set( $name = "Ben" )
The clock is $size$name.

So I guess that's the only way.

Prowler answered 22/10, 2020 at 16:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.