Template system (computing)
   HOME

TheInfoList



OR:

A template processor (also known as a template engine or template parser) is software designed to combine templates with a data model to produce result documents. The language that the templates are written in is known as a template language or templating language. For purposes of this article, a result document is any kind of formatted output, including
documents A document is a writing, written, drawing, drawn, presented, or memorialized representation of thought, often the manifestation of nonfiction, non-fictional, as well as fictional, content. The word originates from the Latin ''Documentum'', w ...
, web pages, or source code (in
source code generation In computer science, the term automatic programming identifies a type of computer programming in which some mechanism generates a computer program to allow human programmers to write the code at a higher abstraction level. There has been little ...
), either in whole or in fragments. A template engine is ordinarily included as a part of a web template system or application framework, and may be used also as a 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: *
variable Variable may refer to: * Variable (computer science), a symbolic name associated with a value and whose associated value may be changed * Variable (mathematics), a symbol that represents a quantity in a mathematical expression, as used in many ...
s and functions *text replacement *file inclusion (or transclusion) *conditional evaluation and loops


Embedded template engines

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 ‘printf’ 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 (substitute) 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 ''n''th sub-expression. For example, s/(cat, dog)s?/\1s/g replaces all occurrences of "cat" or "dog" with "cats" or "dogs", without duplicating an existing "s": (cat, dog) is the 1st (and only) 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 relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relatio ...
, 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.


Source template

Source templates are traditionally specified: * according to a pre-existing programming language; * according to a specially-defined template language; * according to the features of a hosting software application; or * according to a hybrid combination of some or all of the above.


Template engine

The template engine is responsible for: * connecting to the data model; * processing the code specified in the source templates; and * directing the output to a specific
pipeline Pipeline may refer to: Electronics, computers and computing * Pipeline (computing), a chain of data-processing stages or a CPU optimization found on ** Instruction pipelining, a technique for implementing instruction-level parallelism within a s ...
, text file, or
stream A stream is a continuous body of water, body of surface water Current (stream), flowing within the stream bed, bed and bank (geography), banks of a channel (geography), channel. Depending on its location or certain characteristics, a stream ...
. 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 Web development is the work involved in developing a website for the Internet (World Wide Web) or an intranet (a private network). Web development can range from developing a simple single static page of plain text to complex web applications ...
using a web template system, and it is also applied to other contexts as well.(see e.g., Velocity, TemplateToolkit, Freemarker ).


Document generation

Document generation frameworks typically use template processing as the central model for generating documents.


Source code generation

Source code generation tools support generation of source code (as the result documents) from abstract data models (e.g., UML, relational data, domain-specific enterprise data stores) for particular application domains, particular organizations, or in simplifying the production process for
computer programmer A computer programmer, sometimes referred to as a software developer, a software engineer, a programmer or a coder, is a person who creates computer programs — often for larger computer software. A programmer is someone who writes/creates ...
s.


Software functionality

A
web Web most often refers to: * Spider web, a silken structure created by the animal * World Wide Web or the Web, an Internet-based hypertext system Web, WEB, or the Web may also refer to: Computing * WEB, a literate programming system created by ...
template engine processes web templates and source data (typically from a
relational database A relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relatio ...
) 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 Web most often refers to: * Spider web, a silken structure created by the animal * World Wide Web or the Web, an Internet-based hypertext system Web, WEB, or the Web may also refer to: Computing * WEB, a literate programming system created by ...
.


Comparison

XSLT XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subseque ...
is a template processing model designed by
W3C The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 and led by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working to ...
. It is designed primarily for transformations on XML data (into web documents or other output). Programming languages such as Perl, Python, PHP, Ruby, C#, Java, and Go support template processing either natively, or through add-on libraries and modules. JavaServer Pages, JavaServer Pages is a technology released by Sun for use with the Java programming language. Active Server Pages, ASP 1.0 was originally released for use with Microsoft VBScript and JScript. It was an extension to Microsoft IIS. Genshi (for Python), and eRuby are examples of template engines designed specifically for web application development. Moreover, template processing is sometimes included as a sub-feature of software packages like
text editors A text editor is a type of computer program that edits plain text. Such programs are sometimes known as "notepad" software (e.g. Windows Notepad). Text editors are provided with operating systems and software development packages, and can be us ...
, IDEs and
relational database management system A relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relatio ...
s.


Benefits of using template engines

* encourages organization of source code into operationally-distinct layers (see e.g.,
MVC MVC may refer to: Science and technology * Maximum-value composite procedure, an imaging procedure * Multivariable calculus, a concept in mathematics * Multivariable control, a concept in process engineering * Mechanical vapor compression, a desal ...
) * enhances productivity by reducing unnecessary reproduction of effort * enhances teamwork by allowing separation of work based on skill-set (e.g., artistic vs. technical)


See also

* Document automation *
Document modelling Document modelling looks at the inherent structure in documents. Rather than the structure in formatting which is the classic realm of word-processing tools, it is concerned with the structure in content. Because document content is typically vie ...
*
Domain-specific programming language A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. There are a wide variety of DSLs, ranging ...
* * Internationalization and localization **
Common Locale Data Repository The Common Locale Data Repository Project, often abbreviated as CLDR, is a project of the Unicode Consortium to provide locale data in XML format for use in computer applications. CLDR contains locale-specific information that an operating syst ...
** gettext *
Layout engines {{Unreferenced, date=June 2010 In computing, layout is the process of calculating the position of objects in space subject to various constraints. This functionality can be part of an application or packaged as a reusable component or library. Exa ...
* Macro (computer science) * Templates * Template systems * Web template system **
Comparison of web template engines The following table lists the various web template engines used in Web template systems and a brief rundown of their features. See also * Template processor * Web template system A web template system in web publishing lets web designers ...


References


External links


Enforcing Strict Model-View Separation in Template Engines
{{Computer language Scripting languages