Template processor
Encyclopedia
A template processor
is software or a software component that is designed to combine one or more
templates with a data model
Data model
A data model in software engineering is an abstract model, that documents and organizes the business data for communication between team members and is used as a plan for developing applications, specifically how data is stored and accessed....

 to produce
one or more result documents.
For purposes of this article, a result document is any
kind of formatted output, including documents, web page
Web page
A web page or webpage is a document or information resource that is suitable for the World Wide Web and can be accessed through a web browser and displayed on a monitor or mobile device. This information is usually in HTML or XHTML format, and may provide navigation to other web pages via hypertext...

s, or source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

, either in whole or in fragments.

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
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

, an alternate format of flat file database
Flat file database
A flat file database describes any of various means to encode a database model as a single file .- Overview :...

, a spreadsheet
Spreadsheet
A spreadsheet is a computer application that simulates a paper accounting worksheet. It displays multiple cells usually in a two-dimensional matrix or grid consisting of rows and columns. Each cell contains alphanumeric text, numeric values or formulas...

 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, text file
    Text file
    A text file is a kind of computer file that is structured as a sequence of lines of electronic text. A text file exists within a computer file system...

    , or stream


Additionally some template engines allow additional configuration options.

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
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

. 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
Web development is a broad term for the work involved in developing a web site for the Internet or an intranet . This can include web design, web content development, client liaison, client-side/server-side scripting, web server and network security configuration, and e-commerce development...

 using a web template system
Web template system
A Web template system describes the software and methodologies used to produce web pages and for deployment on websites and delivery over the Internet. Such systems process web templates, using a template engine...

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

Source code generation

Source code generation tools support generation of source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

 (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 programmers.

Software functionality

A web
World Wide Web
The World Wide Web is a system of interlinked hypertext documents accessed via the Internet...

 template engine processes web templates and source data (typically from a relational database
Relational database
A relational database is a database that conforms to relational model theory. The software used in a relational database is called a relational database management system . Colloquial use of the term "relational database" may refer to the RDBMS software, or the relational database itself...

) to produce one or more output web page
Web page
A web page or webpage is a document or information resource that is suitable for the World Wide Web and can be accessed through a web browser and displayed on a monitor or mobile device. This information is usually in HTML or XHTML format, and may provide navigation to other web pages via hypertext...

s or page fragments. It is ordinarily included as a part of a web template system
Web template system
A Web template system describes the software and methodologies used to produce web pages and for deployment on websites and delivery over the Internet. Such systems process web templates, using a template engine...

 or application framework
Application framework
In computer programming, an application framework consists of a software framework used by software developers to implement the standard structure of an application for a specific development environment ....

. Currently, template processing software is most frequently used in the context of development for the web
World Wide Web
The World Wide Web is a system of interlinked hypertext documents accessed via the Internet...

.

Comparison

XSLT
XSLT
XSLT is a declarative, XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one. The new document may be serialized by the processor in standard XML syntax or in another format,...

 is a template processing model designed by W3C. It is designed primarily for transformations on XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

 data (into web document
Web document
A web document is similar in concept to a web page, but also satisfies the following broader definition:The term "web document" has been used as a fuzzy term in many sources A web document is similar in concept to a web page, but also satisfies the following broader (W3C) definition:The term "web...

s or other output).

Programming languages such as Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

, PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

, Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

, C#, and Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 support template processing either natively, or through add-on libraries and modules. JavaServer Pages
JavaServer Pages
JavaServer Pages is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types...

, Active Server Pages
Active Server Pages
Active Server Pages , also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for dynamically-generated Web pages. Initially released as an add-on to Internet Information Services via the Windows NT 4.0 Option Pack Active Server Pages (ASP), also known as Classic...

, Genshi
Genshi (templating language)
Genshi is a template engine for XML-based vocabularies written inPython. Genshi is used to easily insert generated output into XML-based languages, usually HTML, and reuse elements between documents...

 (for Python), and eRuby
ERuby
eRuby is a templating system that embeds Ruby into a text document. It is often used to embed Ruby code in an HTML document, similar to ASP, JSP and PHP.-Usage:eRuby allows Ruby code to be embedded within a pair of delimiters...

 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, IDE
Integrated development environment
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...

s and relational database management system
Relational database management system
A relational database management system is a database management system that is based on the relational model as introduced by E. F. Codd. Most popular databases currently in use are based on the relational database model....

s.

Benefits of using template engines

  • encourages organization of source code into operationally-distinct layers (see e.g., MVC
    Model-view-controller
    Model–view–controller is a software architecture, currently considered an architectural pattern used in software engineering. The pattern isolates "domain logic" from the user interface , permitting independent development, testing and maintenance of each .Model View Controller...

    )
  • 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

  • Template engine (web)
  • Source code generation
  • Macro preprocessor
  • Preprocessor
    Preprocessor
    In computer science, a preprocessor is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers...

  • Domain-specific programming language
    Domain-specific programming language
    In software development and domain engineering, a domain-specific language is a programming language or specification language dedicated to a particular problem domain, a particular problem representation technique, and/or a particular solution technique...


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK