[2024]Digital Global Overview Report 2024 Meltwater.pdf
Using velocity Templates(An overview)
1.
2. A template engine is a software development
tool that allows you to create and render
documents that format and present your data
.
A template engine is included as part of
a template system or application
framework
Content from a database and "presentation
specifications" (in a web template), are
combined (through the template engine) to
produce web documents.
4. Template engines generally include features common in
higher level programming with emphasis on processing
plain text
Features include:
Variables and functions
Text replacement
File inclusion
Conditional evaluation and loops
5. Velocity Template Engine
It permits the templates to reference methods defined in Java
code using Velocity template language(VTL) statements.
VTL uses references to embed dynamic content in a text
product
References are of three types variables, properties and Methods
VTL REFERENCES
Variable ${aVariable}, $aVariable
Properties ${anIdentifier.aIdentifier}
Methods ${aIdentifier.aMethodBody(${aIdentifier})}
6. References begin with $ and are used to get something
Directives begin with # and are used to do something
#set is used to assign a value to a variable
The variable, $aVariable can the be used in the template
to output the value(i.e “aValue”)
#set($ aVariable = “aValue”)
Character
directive
Variable
Value
7. Lets Work!!
Download velocity engine (Velocity-1.7 jar) from
http://velocity.apache.org/download.cgi
Include the Velocity-1.7 jar jar in the lib folder of your
project folder(you may also have to include commons-
collections.jar, commons-lang and mail.jar).
Prepare your .vsl template message
Write your java code
8. Template Message
#*
Test E-mail Message
@zed
*#
Dear Mr $recepientName,
The management of $companyName hereby invite you for an
interview in $interviewVenue at $timeOfInterview .
Yours Sincerely,
$sendersName