Questions tagged [vtl]

The Velocity Template Language (VTL) is meant to provide the easiest, simplest, and cleanest way to incorporate dynamic content in a web page.

VTL is the Velocity Template Language.

It includes Variables, Properties, Methods, Directives, Macros, and more...

Reference: http://velocity.apache.org/engine/2.0/vtl-reference.html

193 questions
56
votes
5 answers

Is there a way to generate multiple files/classes with intellij code/file templates?

I like intellij's code/file templates, they are working really well for me for single files but it would be great to be able to create multiple files/classes at once. I did find this question but since it has been a few years since I was hoping that…
Trevor Gowing
  • 2,236
  • 22
  • 25
45
votes
3 answers

Create and iterate through an array in Velocity Template Language

How to create an array in VTL and add contents to the array? Also how to retrieve the contents of the array by index?
raghav
  • 451
  • 1
  • 4
  • 4
43
votes
1 answer

Replace a Substring of a String in Velocity Template Language

I want to replace a part of a string in Velocity Template Language with another string. For Example: #set($a = "Hello") #set($b = "+") I want to replace ll in Hello with ++. The output should be He++o Please help me Thanks Kishore
kishore
  • 431
  • 1
  • 4
  • 4
14
votes
3 answers

How can I write unit tests for velocity templates?

Is this even possible? Hello friends. I'm in the process of building an application using AWS AppSync + DynamoDB and I'm starting to have quite a large pile of resolver mapping templates, all which are written using the Apache Velocity Template…
13
votes
1 answer

Output part of a string in velocity

apologies if I waffle or talk a bit of jibberish but I'm new to velocity, and these forums! I need to check the contents of a string for a certain character and output the second part of the text if it appears. For example: set ($string = "This is a…
OnionSandwich
  • 237
  • 1
  • 3
  • 9
12
votes
3 answers

Is there a way to debug Velocity templates in the traditional code debugging sense?

We make heavy use of Velocity in our web application. While it is easy to debug the Java side of things and ensure the Velocity Context is populated correctly, it would be extremely valuable to be able to step through the parsing of the VTL on the…
Peter
  • 29,498
  • 21
  • 89
  • 122
11
votes
3 answers

Adding a key/value pair to an object in VTL (for API Gateway)

I am writing a mapping template for an AWS API Gateway integration response. I would like to add a key/value pair to the JSON object returned my Lambda function. My function returns some JSON like this: { "id": "1234", "name": "Foo…
Josh Glover
  • 25,142
  • 27
  • 92
  • 129
11
votes
4 answers

How to access an object's public fields from a Velocity template

Here is my object class: public class Address { public final String line1; public final String town; public final String postcode; public Address(final String line1, final String town, final String postcode) { this.line1…
Alex Spurling
  • 54,094
  • 23
  • 70
  • 76
9
votes
1 answer

How to check if value exists in an array using Velocity Template Language

I am not sure how I could achieve the following using Velocity Template Language. Essentially, I'd like to check if a given value exists from the given list/array. In C#, it's equivalent to .Any() or .Contains() method. #set($myValues = ["apple",…
woodykiddy
  • 6,074
  • 16
  • 59
  • 100
9
votes
2 answers

AppSync GraphQL mutation server logic in resolvers

I am having issues finding good sources for / figuring out how to correctly add server-side validation to my AppSync GraphQL mutations. In essence I used AWS dashboard to define my AppSync schema, hence had DynamoDB tables created for me, plus some…
Ilja
  • 44,142
  • 92
  • 275
  • 498
8
votes
3 answers

How to return directly from the request mapper?

Consider the following GraphQL template: type Foo { id: ID! bars: Bars } type Bar { id: ID! name: String! } type Bars { items: [Bar]! nextToken: String } The mapping template for the bars field in the Foo type looks like…
Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62
8
votes
3 answers

AWS API Gateway - How do I get the date/timestamp/epoch in a body mapping template?

I need to include the request time in the body mapping template for an API Gateway method. Is there a date/time variable or function? I couldn't find anything in the template reference. Example body mapping…
John Himmelman
  • 21,504
  • 22
  • 65
  • 80
7
votes
1 answer

How to throw an user-defined exception from Velocity Template Script (VTL)?

How to throw an user-defined exception from Velocity Template Script (VTL) ? From my velocity script, i need to throw an exception based on a condition, so that the caller can catch the exception and present an useful error messages to the end…
anuu_online
  • 374
  • 1
  • 3
  • 14
6
votes
3 answers

AppSync BatchPutItem not saving items

I'm trying to batch put a number of items to DynamoDB using AppSync. When I call the resolver it throws no errors but nothing is saved to the database. Schema type BoxScore @model { id: ID! userId: String! gameVariant: String! complete:…
Max Phillips
  • 6,991
  • 9
  • 44
  • 71
6
votes
2 answers

How to add functions like generating random UUID in velocity template for request/response mapping in API gateway

I am creating a request mapping template for AWS API gateway. In that template I want to customize the request params based on certain conditions and apply operators. #foreach($header in $input.params().header.keySet()) …
Ali
  • 253
  • 4
  • 13
1
2 3
12 13