Templating, Template Engines and Apache Velocity!!!

A Template Engine (or a Template Processor) is a piece of software or a software component that is designed to combine one or more templates with a data model to produce one or more result documents.

The language that the templates are written in is known as a Template Language.

A Template Engine is ordinarily included as a part of an application framework, and may be used also as preprocessor or filter.

Typical Features

Template Engines typically include features common to most high-level programming languages, with an emphasis on features for processing plain text. Such features include:
  • variables and functions
  • text replacement
  • file inclusion
  • conditional evaluation and loops

System Elements

Template Processing systems consist of these primary elements:
  • an associated data model
  • one or more source templates
  • a processor or template engine

Data Model
This may be a relational database, a source file such as XML, an alternate format of flat file database, a spreadsheet or any of other various sources of pre-formatted data.

Some template processing systems are limited in the types of data that can be used. Others are designed for maximum flexibility and allow many different types of data.

Source Template
Source templates are traditionally specified according to either of the following:
  • a pre-existing programming language
  • a specially-defined template language

Template Engine
The Template Engine is responsible for:
  • connecting to the data model.
  • processing the code specified in the source templates.
  • directing the output to a specific text file or a stream.


Apache Velocity Engine

The Apache Velocity Engine is a Template Engine.

Velocity permits you to use a simple yet powerful scripting language (Velocity Template Language - VTL) to reference objects defined in Java code. It is written in 100% pure Java and can be easily embedded into your own applications.
<html>
    <body>
       #set($foo = "Velocity")
       Hello $foo World!
    </body>
</html>