Questions tagged [velocity-template-language]

Velocity Template Language - VTL

Apache Velocity first released in April 2001, is a Java-based template engine that provides a template language VTL to reference objects defined in Java code. It aims to ensure clean separation between the presentation tier and business tiers in a Web application (the model–view–controller design pattern).

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

Official documentation.

33 questions
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…
6
votes
0 answers

How to write Upsert mutation query(insert or update) in AWS DynamoDB AppSync resolver

I am working on DynamoDB with the help of AppSync GraphQL queries. I have a one DynamoDB table in which username is Partition key(hash key) and timestamp_value is sort key(range key). I am saving two things against one item i.e. one is reading and…
6
votes
2 answers

get particular value by key from Hashmap in velocity template

i have a java code like below public static void main(String args[]) throws Exception { VelocityEngine engine = new VelocityEngine(); engine.init(); Template template = engine.getTemplate("userinfo.vm"); VelocityContext vc = new…
daisy
  • 357
  • 3
  • 7
  • 22
5
votes
2 answers

Velocity template as a String in Java

I have a java String which is basically a velocity template. String vt = "#foreach ($number in [1..34]) $number += $number #end" String result = *String_vt_calculated_by_Velocity_Engine*; System.out.println(result); How can I evaluate the above…
AKumar
  • 95
  • 2
  • 14
3
votes
0 answers

code style for velocity template files in IntelliJ

Problem The automatic indents in .vm files don't behave as I want them to. Below I add the auto formatted file and also the formatting I want. The following code snippet is auto formatted by…
2
votes
1 answer

Remove certain element from array in Velocity Template Language (VTL)

I would like to remove a certain element from an array in Velocity Template Language. I did not find any appropriate method looking through the documentation of Apache VTL, that's why I am asking here for help. I have tried following (.remove()…
1
vote
1 answer

Convert XML object to Json using velocity template

I have a use-case where input data is in xml format. It contains multiple fields where we are interested in reading only few fields. Based on the different use-case, separate velocity templates would have to written to convert xml to json data. I…
Amit Kumar
  • 377
  • 4
  • 17
1
vote
0 answers

How will add global variable in velocity template html so that global variable to reset to initial values

Example: Initial currentpageNo is 1 in velocity context. set($currentpageNo=$currentpageNo+1) $currentpageNo For each page Current page value is 2 But require is it should increase. Please let me know if there is any possiable way
1
vote
1 answer

Switch Image on Desktop and Mobile for email | Mailjet

We are switching to use Mailjet API for sending emails. One problem we are facing right now: We are using apache velocity template for html body where we give image url in src tag in html. But we have different image for desktop, mobile/ipad for…
1
vote
2 answers

Converting velocity template in api gateway to be passed in typescript with AWS CDK

I'm using typescript with AWS CDK to generate a cloudFormation template for api gateway. I've a Apache Velocity template that helps me convert my response. While I'm creating the API gateway using typescript. How can I pass the template from code…
1
vote
3 answers

Create a reusable parse method which uses velocity

We are using velocity to parse our templates. Velocity developer guide suggests to create a new VelocityContext for every parsing But what about the VelocityEngine and the RuntimeInstances? Can we reuse them or is it better to create new instances…
Crusaderpyro
  • 2,163
  • 5
  • 29
  • 53
1
vote
0 answers

Extract the year in Velocity Template Language - Python

I was referring to this to print the author information as header on each python script. The document shows an example for printing the date information - # Created by ${USER} at ${DATE} This prints the entire date in DD-MM-YYYY format. However, I…
amitection
  • 2,696
  • 8
  • 25
  • 46
1
vote
1 answer

Velocity Template Language: Connect two conditions in one #elseif() statement

In my example the parameters are: $p2.length which has the value "0" and the boolean $suspectYesNo which is set to "false". I would expect, that in my code the second #elseif will run due to my set parameters, but however it shows up that "Code 4…
1
vote
1 answer

Velocity Template Engine plugin or extension?

Has anyone tried building Velocity template engine extension or plugin? Our team is heavily using Velocity Template Language for API input/output transformations. Since a lot of complex logic is in the VTL code, we have implemented a way to unit…
0
votes
1 answer

AWS Appsync Subscription with CDK and without Amplify

How can I create an AppSync Subscription with AWS CDK? I am able to successfully create Queries and Mutations, but I'm having trouble with Subscriptions. Is it possible? If so, how can I achieve it? This is how I'm currently attempting…
Viktor
  • 93
  • 1
  • 6
1
2 3