Template engine (web)
From Wikipedia, the free encyclopedia
This article does not cite any references or sources. Please help improve this article by adding citations to reliable sources (ideally, using inline citations). Unsourced material may be challenged and removed. (June 2008) |
|
A (web) template engine is software that is designed to process web templates and content information to produce output web documents. It runs in the context of a template system.
Contents |
[edit] Types
Template engine is ordinarily included as a part of a web template system or application framework, and may be used also as preprocessor, filter, or template processor. Currently, template processing software is most frequently used in the context of development for the web.
XSLT is a template processing model designed by W3C. It is designed primarily for transformations on XML data (into web documents or other output).
Programming languages such as Perl, Ruby, C, and Java support template processing either natively, or through add-on libraries and modules. JavaServer Pages (JSP), PHP, and Active Server Pages (ASP with VBScript, JScript or other languages) are examples, themselves, of web template engines.
[edit] 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 (or transclusion)
- conditional evaluation and loops
[edit] Example
The accompanying illustration depicts a simplified processing model for a typical web template engine. The template engine produces a web page by processing the web template source file along with data from a relational database. The template engine replaces variables with specific values. In the illustration, substitution of $X
by the database content (in page 01 "Mother", on page 02 "World").
A web template might look like this:
<html> <h1>Hello {$X}</h1> </html>
With additional template source code ...
templateAssign ('X', 'World');
... or, when specifying the relational database context:
$data[01]='Mother'; $data[02]='World'; templateAssign('X', $data[$i]);
[edit] Benefits
Benefits of using template engines include:
- Encouraging organization of source code into operationally-distinct layers (see e.g., MVC)
- Enhancing productivity by reducing unnecessary reproduction of effort
- Enhancing teamwork by allowing separation of work based on skill-set (e.g., artistic vs. technical)
[edit] Comparison
The following table lists the various template engines discussed on Wikipedia and a brief rundown of their features. The content here is a work-in-progress.
Engine (Implementation) | Languages | License | Platform | Variables | Functions | Includes | Conditional Inclusion | Looping | Evaluation (Language) | Assignment | Errors & Exceptions |
---|---|---|---|---|---|---|---|---|---|---|---|
StringTemplate | Java (native), Python, C# | open-source? | Cross-Platform | Yes | No | Yes | Yes | Yes | No | No | No |
ASP.net (Microsoft) | C#, VB.net | Proprietary | Microsoft Windows | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
ASP.net (Mono) | C# | GNU LGPL | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
Apache Velocity | Java, C# | Apache License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
Beilpuz | PHP 5 | GNU LGPL | Cross-Platform | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes |
CheetahTemplate | Python | MIT License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
Chip Template Engine | PHP, Perl | open-source? | Cross-Platform | Yes | Yes | Yes | Yes | Yes | No | Yes | No |
CTPP | C, C++, Perl, PHP, Python | BSD-like | Cross-Platform | Yes | Yes | Yes | Yes | Yes | No | No | Yes |
Dwoo | PHP 5 | GNU LGPL | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (PHP) | Yes | Yes |
Dylan Server Pages | Dylan language | unknown | unknown | Yes | Yes | Yes | Yes | No? | No | No | No |
eRuby | Ruby | open-source? | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
Evoque Templating | Python, Py3K | AFL v3.0 | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Python) | No | Yes |
FreeMarker | Java | BSD-like | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
Genshi (templating language) | Python | BSD-like | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Python) | Yes | Yes |
GvTags | Groovy | Apache License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Groovy) | Yes | No |
H2o | PHP, Ruby | MIT License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes |
Haml | Ruby, PHP (WIP) | MIT License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Ruby) | Yes | Yes |
Hamlets | Java | BSD | Cross-Platform | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes |
JSP Weaver | Java | Proprietary | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
Jasper framework | Perl, PHP, C#, Java | open-source? | Cross-Platform | Yes | No | No | No | No | No | No | No |
JavaServer Pages | Java | Proprietary | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
Jinja | Python | BSD | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Python) | Yes | No |
Kalahari | Python | BSD-like | Cross-Platform | Yes | Yes | Through inheritance | No | Yes | No | Yes | Yes |
Kid (templating language) | Python | open-source? | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Python) | Yes | Yes |
Mako | Python | MIT | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Python) | Yes | No |
Mars-Templater | PHP 5 | MIT License | Cross-Platform | Yes | No | No | Yes | Yes | No | No | No |
pyratemp | Python | MIT | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Python) | No? | No |
MiniTemplator | PHP, Java, VB.net | GNU LGPL | Cross-Platform | Yes | Yes | Yes | Yes | Yes | No | No | No? |
Template Blocks | PHP 5 | GNU GPL | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (PHP) | Yes | Yes? |
Open Power Template | PHP 5 | GNU LGPL | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (PHP) | No | No |
Outline | PHP 5 | open-source | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (PHP) | Yes | Yes? |
PHAML | PHP | MIT License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (PHP) | Yes | Yes? |
Phammable | PHP 5 | GNU GPL | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (PHP) | Yes | Yes |
Smarty | PHP | GNU LGPL | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (PHP) | Yes | Yes? |
Template Attribute Language | Python, PHP 5 | open-source | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
TinyButStrong | PHP | open-source? | Cross-Platform | Yes | No | Yes | No | Yes | No | No | No |
Vemplator | PHP | MIT License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (PHP) | No | No |
vlibTemplate | PHP | Artistic License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | No | No | No |
Deihro TemplateEngine | PHP | open-source | Cross-Platform | Yes | Yes | indirect | No | No | No | No | No |
Template Toolkit | Perl | open-source | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Perl) | Yes | Yes |
WebMacro | Java | open-source? | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
QueryTemplates | PHP 5, JavaScript | MIT License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
FastTemplate | PHP | Artistic License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | No | Yes | No |
[edit] See also
- Template processor
- Layout engine
- Category:Template engines
- Macro preprocessor
- Preprocessor
- Smarty (PHP: Template engine)
- Mytemplate (PHP: MyTemplate engine)
- vlibTemplate (PHP: Template engine)
- Jasper framework
- Virtual machine
- Bytecode