While template processors are typically a separate piece of software, used as part of a system or framework, simple templating languages are commonly included in the string processing features of general-purpose programming languages, and in text processing programs, notably text editors or word processors. The templating languages are generally simple substitution-only languages, in contrast to the more sophisticated facilities in full-blown template processors, but may contain some logic. Simple examples include print format strings, found in many programming languages, and snippets, found in a number of text editors and source code editors. In word processors, templates are a common feature, while automatic filling in of the templates is often referred to as mail merge. An illustrative example of the complementary nature of parsing and templating is the s command in the sed text processor, originating from search-and-replace in the ed text editor. Substitution commands are of the form s/regexp/replacement/, where regexp is a regular expression, for parsing input, and replacement is a simple template for output, either literal text, or a format string containing the characters & for "entire match" or the special escape sequences\1 through \9 for the nth sub-expression. For example, s/s?/\1s/g replaces all occurrences of "cat" or "dog" with "cats" or "dogs", without duplicating an existing "s": is the 1st sub-expression in the regexp, and \1 in the format string substitutes this into the output.
System elements
All template processing systems consist of at least these primary elements:
an associated data model;
one or more source templates;
a processor or template engine;
generated output in the form of result documents.
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 preformatted 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.
Template engine
The template engine is responsible for:
connecting to the data model;
processing the code specified in the source templates; and
Additionally some template engines allow additional configuration options.
Result documents
These may consist of an entire document or a document fragment.
Uses
Template processing is used in various contexts for different purposes. The specific purpose is ordinarily contingent upon the software application or template engine in use. However, the flexibility of template processing systems often enables unconventional uses for purposes not originally intended by the original designers.
Template engine
A template engine is a specific kind of template processing module that exhibits all of the major features of a modern programming language. The term template engine evolved as a generalized description of programming languages whose primary or exclusive purpose was to process templates and data to output text. The use of this term is most notably applied to web development using a web template system, and it is also applied to other contexts as well.
Document generation
Document generation frameworks typically use template processing as the central model for generating documents.
Software functionality
A web template engine processes web templates and source data to produce one or more output web pages or page fragments. It is ordinarily included as a part of a web template system or application framework. Currently, template processing software is most frequently used in the context of development for the web.