Template engine (web)
From Wikipedia, the free encyclopedia
This article does not cite any references or sources. (June 2008) Please help improve this article by adding citations to reliable sources. Unverifiable material may be challenged and removed. |
This article is part of |
Main:
|
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] Specific types of template engines
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] A web template 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 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)
[edit] Comparison of template engines
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 | 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 | 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 |
Haml | Ruby, PHP (WIP) | MIT License | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Ruby) | 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 (Template engine) | Python | BSD-like | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Python) | Yes | No |
Kid (templating language) | Python | open-source? | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (Python) | Yes | Yes |
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? |
Smarty | PHP | GNU LGPL | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (PHP) | Yes | Yes? |
TinyButStrong | PHP | open-source? | Cross-Platform | Yes | No | Yes | No | Yes | No | No | No |
Vemplator | PHP | MIT | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes (PHP) | No | No |
VlibTemplate | PHP | open-source? | 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 |
WebMacro | Java | open-source? | Cross-Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
[edit] See also
- Template processor
- Layout engine
- Category:Template engines
- Macro preprocessor
- Preprocessor
- Smarty (PHP: Template engine)
- vlibTemplate (PHP: Template engine)
- Jasper framework
- Virtual machine
- Bytecode
[edit] External links
Other template engines on template systems:
- Blitz templates (PHP-module, written in C, very fast, OO, MVC), documentation. Probably the fastest engine for PHP, see benchmarks, Simple Blitz tutorial
- php_templates (PHP-module, written in C, very fast)
- Beilpuz (PHP 5)
- CT++ Crossplatform C/C++/Perl and PHP Template engine
- Chip
- Contemplate
- Dwoo (PHP 5, mostly Smarty compatible)
- Enforcing Strict Model-View Separation in Template Engines
- Evoque Templating - sandbox-able, lightweight, fast text templating for Python, with automatic Cross-site scripting protection
- Galena: Another Ruby Template Engine
- Liquid Ruby template engine
- Matlab template engine
- FreeMarker
- HTML_Template_IT
- patTemplate
- SmartTemplate
- Smarty
- startonweb
- StringTemplate
- Template::Toolkit
- Template::Alloy
- Template Lite
- TinyButStrong
- vLIB
- Vemplator
- Acceleo - MDA template based Code generator based on Eclipse and EMF
- Outline - PHP template engine, borrows from Smarty and PHP syntax - very small footprint
Template engine usage: