HOME

TheInfoList




A template processor (also known as a template engine or template parser) is
software Software is a collection of instructions Instruction or instructions may refer to: Computing * Instruction, one operation of a processor within a computer architecture instruction set * Computer program, a collection of instructions Music * I ...

software
designed to combine templates with a
data model A data model (or datamodel) is an abstract model that organizes elements of data and standardizes how they relate to one another and to the properties of real-world entities. For instance, a data model may specify that the data element representing ...

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'', which ...

documents
,
web page A web page (or webpage) is a hypertext Hypertext is text displayed on a or other with references () to other text that the reader can immediately access. Hypertext documents are interconnected by hyperlinks, which are typically acti ...

web page
s, or
source code In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and ...

source code
(in
source code generation In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algori ...
), either in whole or in fragments. A template engine is ordinarily included as a part of a
web template system A web template system in web publishing lets web designers and developers work with ''web templates'' to automatically generate custom web page A web page (or webpage) is a hypertext Hypertext is text displayed on a or other wi ...
or
application framework In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task. Programming involves tasks such as: analysis, generati ...
, and may be used also as a
preprocessor In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algori ...

preprocessor
or
filter Filter, filtering or filters may refer to: Science and technology Device * Filter (chemistry), a device which separates solids from fluids (liquids or gases) by adding a medium through which only the fluid can pass ** Filter (aquarium), critical ...
.


Typical features

Template engines typically include features common to most high-level
programming languages A programming language is a formal language comprising a set of Formal language#Words over an alphabet, strings that produce various kinds of Machine code, machine code output. Programming languages are one kind of computer language, and are us ...
, with an emphasis on features for processing
plain text In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and sof ...

plain text
. Such features include: * variables and
functions Function or functionality may refer to: Computing * Function key A function key is a key on a computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically. Modern comp ...
*text replacement *file inclusion (or
transclusion In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Alg ...
) *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 language In computer software Software is a collection of Instruction (computer science), instructions and data (computing), data that tell a computer how to work. This is in contrast to Computer hardware, physical hardware, from which the system is bu ...
s, and in text processing programs, notably
text editor A text editor is a type of computer program In imperative programming, a computer program is a sequence of instructions in a programming language that a computer can execute or interpret. In declarative programming, a ''computer program'' is ...

text editor
s or
word processor A word processor (WP) is a device or computer program that provides for input, editing, formatting, and output of text, often with some additional features. Early word processors were stand-alone devices dedicated to the function, but current ...
s. 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 editor A source-code editor is a text editor A text editor is a type of computer program In imperative programming, a computer program is a sequence of instructions in a programming language that a computer can execute or interpret. In declarati ...
s. In word processors,
templates Template may refer to: Tools * Die (manufacturing), used to cut or shape material * Mold, in a molding (process), molding process * Stencil, a pattern or overlay used in graphic arts (drawing, painting, etc.) and sewing to replicate letters, shap ...
are a common feature, while automatic filling in of the templates is often referred to as
mail mergeMail merge consists of combining mail and Letter (message), letters and pre-addressed envelopes or mailing labels for mass mailings from a form letter. This feature is usually employed in a word processor, word processing document which contains fix ...
. An illustrative example of the complementary nature of
parsing Parsing, syntax analysis, or syntactic analysis is the process of analyzing a string String or strings may refer to: *String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other obj ...

parsing
and templating is the s (substitute) command in the
sed sed ("stream editor") is a Unix Unix (; trademarked as UNIX) is a family of Computer multitasking, multitasking, multiuser computer operating systems that derive from the original AT&T Corporation, AT&T Unix, whose development started in th ...
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 A regular expression (shortened as regex or regexp; also referred to as rational expression) is a sequence of Character (computing), characters that specifies a ''search pattern matching, pattern''. Usually such patterns are used by string-se ...
, 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 sequence In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algo ...
s \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 source file such as
XML Extensible Markup Language (XML) is a markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntactically distinguishable fro ...

XML
, an alternate format of
flat file database Image:Flat File Model.svg, 280px, Example of a flat file modelbyte.html" ;"title="hex dump of the 318 byte">hex dump of the 318 byte Wikipedia favicon, or . The first column numerates the line's starting address, while the * indicates repetition ...
, a
spreadsheet A spreadsheet is a computer application for organization, analysis, and storage of data in table (information), tabular form. Spreadsheets were developed as computerized analogs of paper accounting Worksheet#Accounting, worksheets. The program op ...

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 si ...
,
text file A text file (sometimes spelled textfile; an old alternative name is flatfile) is a kind of computer file A computer file is a computer resource for recording data Data (; ) are individual facts, statistics, or items of information, oft ...
, or
stream A stream is a body of water (Lysefjord) in Norway Norway, officially the Kingdom of Norway,Names in the official and recognised languages: Bokmål Bokmål (, ; literally "book tongue") is an official written standard for the No ...
. 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 Application software (app for short) is computing software designed to carry out a specific task other than one relating to the operation of the computer itself, typically to be used by end-users. Examples of an application Application may refer ...
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 A programming language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbol (formal), letters are taken from an alphabet (computer science) ...

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 Web site, website for the Internet (World Wide Web) or an intranet (a private network). Web development can range from developing a simple single Static Web page, static page of plain text to co ...
using a
web template system A web template system in web publishing lets web designers and developers work with ''web templates'' to automatically generate custom web page A web page (or webpage) is a hypertext Hypertext is text displayed on a or other wi ...
, 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 In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and ...

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 called a software developer, a programmer or more recently a coder (especially in more informal contexts), is a person who creates computer software Software is a collection of Instruction (computer science) ...
s.


Software functionality

A
web Web most often refers to: * Spider web A spider web, spiderweb, spider's web, or cobweb (from the archaic word '' coppe'', meaning "spider") is a structure created by a spider Spiders ( order Araneae) are air-breathing arthropod An ar ...
template engine processes web templates and source data (typically from a
relational database A relational database is a digital database In , a database is an organized collection of stored and accessed electronically from a . Where databases are more complex they are often developed using formal techniques. The (DBMS) is the tha ...
) to produce one or more output
web page A web page (or webpage) is a hypertext Hypertext is text displayed on a or other with references () to other text that the reader can immediately access. Hypertext documents are interconnected by hyperlinks, which are typically acti ...

web page
s or page fragments. It is ordinarily included as a part of a
web template system A web template system in web publishing lets web designers and developers work with ''web templates'' to automatically generate custom web page A web page (or webpage) is a hypertext Hypertext is text displayed on a or other wi ...
or
application framework In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task. Programming involves tasks such as: analysis, generati ...
. Currently, template processing software is most frequently used in the context of development for the
web Web most often refers to: * Spider web A spider web, spiderweb, spider's web, or cobweb (from the archaic word '' coppe'', meaning "spider") is a structure created by a spider Spiders ( order Araneae) are air-breathing arthropod An ar ...
.


Comparison

XSLT XSLT (Extensible Stylesheet Language Transformations) is a language for XML transformation language, transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may s ...

XSLT
is a template processing model designed by
W3C The World Wide Web Consortium (W3C) is the main international standards organization A standards organization, standards body, standards developing organization (SDO), or standards setting organization (SSO) is an organization whose primary ...

W3C
. It is designed primarily for transformations on
XML Extensible Markup Language (XML) is a markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntactically distinguishable fro ...

XML
data (into web documents or other output).
Programming languages A programming language is a formal language comprising a set of Formal language#Words over an alphabet, strings that produce various kinds of Machine code, machine code output. Programming languages are one kind of computer language, and are us ...
such as
Perl Perl is a family of two high-level High-level and low-level, as technical terms, are used to classify, describe and point to specific Objective (goal), goals of a systematic operation; and are applied in a wide range of contexts, such as, for ...
,
Python PYTHON was a Cold War contingency plan of the Government of the United Kingdom, British Government for the continuity of government in the event of Nuclear warfare, nuclear war. Background Following the report of the Strath Committee in 1955, the ...
,
PHP PHP is a general-purpose scripting language A scripting language or script language is a programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various k ...

PHP
,
Ruby A ruby is a pink-ish red to blood-red colored gemstone A gemstone (also called a fine gem, jewel, precious stone, or semi-precious stone) is a piece of mineral In geology and mineralogy, a mineral or mineral species is, broadly spea ...
, C#,
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 147.7 million people, Java is the world's List of ...
, and Go support template processing either natively, or through add-on libraries and modules.
JavaServer Pages Jakarta Server Pages (JSP; formerly JavaServer Pages) is a collection of technologies that helps software developers create dynamic web page, dynamically generated web pages based on HTML, XML, SOAP, or other document types. Released in 1999 by Sun ...
, JavaServer Pages is a technology released by Sun for use with the Java programming language.
Active Server Pages Active Server Pages (ASP) is Microsoft Microsoft Corporation is an American multinational corporation, multinational technology company, technology corporation which produces Software, computer software, consumer electronics, personal com ...
, 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 eRuby (Embedded Ruby) is a templating system that embeds Ruby programming language, Ruby into a text document. It is often used to embed Ruby code in an HTML document, similar to Active Server Pages, ASP, JavaServer Pages, JSP and PHP and other se ...
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, following the naming of Microsoft Notepad. Text editors are provided with operating systems and software development pac ...
,
IDE #REDIRECT IDE IDE, iDE, or Ide may refer to: Organisations * ''Institut für Dokumentologie und Editorik'', a German think tank for the application of digital methods on historical documents * Institute of Developing Economies, a semi-governmental ...
s and
relational database management system A relational database is a digital database In computing, a database is an organized collection of Data (computing), data stored and accessed electronically from a computer system. Where databases are more complex they are often developed usin ...
s.


Benefits of using template engines

* encourages organization of source code into operationally-distinct layers (see e.g., MVC) * 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 automationDocument automation (also known as document assembly or document management) is the design of systems and workflows that assist in the creation of electronic documents. These include logic-based systems that use segments of pre-existing text and/or ...
*
Document modelling{{multiple issues, {{original research, date=August 2013 {{refimprove, date=September 2014 Document modelling looks at the inherent structure in documents. Rather than the structure in formatting which is the classic realm of word-processing tools ...
*
Domain-specific programming languageA domain-specific language (DSL) is a computer languageA computer language is a method of communication with a computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically. M ...
* *
Internationalization and localization In computing, internationalization and localization (American English, American) or internationalisation and localisation (British English), often abbreviated i18n and L10n, are means of adapting computer software to different languages, regional ...
**
Common Locale Data Repository The Common Locale Data Repository Project, often abbreviated as CLDR, is a project of the Unicode Consortium The Unicode Consortium (legally Unicode, Inc.) is a 501(c)(3) A 501(c)(3) organization is a corporation, trust, unincorporated asso ...
**
gettext In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and soft ...

gettext
* Layout engines *
Macro (computer science) A macro (short for "macro instruction", from Greek#REDIRECT Greek Greek may refer to: Greece Anything of, from, or related to Greece Greece ( el, Ελλάδα, , ), officially the Hellenic Republic, is a country located in Southeast Euro ...


References


External links


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