Reputation: 425
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?
Upvotes: 5
Views: 6059
Reputation: 81
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.
Upvotes: 6