Comparison of web template engines

This product was added to computer science because of the content, defects on the quality assurance side of the editor. This is done to bring the quality of the articles from the computer science subject area to an acceptable level. Help us to eliminate the substantive shortcomings of this article and take part you in the discussion! ( )

A template engine (of English. Template and Machine) is a software that fills a file ( the template ) processes, and certain placeholders in it with the current contents. The terms class template and template system are often used as a synonym for a template engine.

Class templates in C programming, however, are not comparable with template engines because they allow independent programming of data type and contain all the classes. In the templates of a template engine is no program code should be included. Control structures ( such as IF ), however, are often possible and used in templates. Typical file types that are processed are HTML, text (ASCII or Unicode), XML, and TeX.

  • 2.1 template engines for PHP 2.1.1 example
  • 2.3.1 Application Example


The concept is similar to the merge fields in a Word Processing: In a document merge fields (placeholders ) inserted as name - Road - place. In template engines these merge fields template variables are called. Then, if several letters are generated from the document, instead of the template variable name is a real name as " William Smith " in the final letter.

The document must be written only once and formatted. All changes automatically affect future created form letters. This is just as in template engines; more parallels with serial letter templates are:

  • The data comes from an external source (database, spreadsheet, etc.).
  • To modify the data, the template does not have to be modified, and vice versa.
  • The template can be reused.


Template engines are often used by programmers to separate from the context of Web applications, program code ( a programming language ) from the design. Just as is shown by manufacturers of some template engines, templates and engines intended by separating the programming logic from the design of the script HTML code exempt and do so more clearly.

This compares with the original idea of ​​the template engines: They should link static text and dynamic content efficiently as possible with each other. Often, template engines are, therefore, just to take in programming languages ​​whose syntax such a mixture does not directly support (eg Java: JSP, VBScript, inter alia: ASP). For a true separation of presentation from data models and the logic components template engines, however, are unsuitable and there are additional concepts such as Model View Controller required.


  • Program code ( PHP, Python, Perl) is separated from the markup (HTML).
  • Designers and developers can work simultaneously on a project.
  • WYSIWYG editors can be used.


Template engines

  • Template engines always produce additional overhead.
  • Template engines have to be learned in use. In addition to the new syntax also often a basic knowledge of object-oriented programming are required.
  • Template engines are restricted to a textual output.

Language-specific template engines

The mass of template engines is enormous. House developments are commonplace. XSLT is a competition for all template engines. In PHP, Smarty is widely used, but has not displaced the developments and other template engines from the market.

Template engines for PHP

PHP itself has been designed so that you can mix programming language constructs with the textual output via placeholders or designated areas.

< php echo $ body_text? ;? >   $ value): ? >    ?

key: < php echo $ key; ? > - Value: < php echo $ value; ? > ? < php endforeach; ? > The advantage is the ease of use. It needs no additional library to be installed, even this procedure is for experienced PHP developers the easiest to understand and follows the principle of least surprise. The use of a separate template engine for PHP is not required. Nevertheless, there are a very large number of engines especially for PHP.

  • Smarty
  • Twig
  • Fluid (as part of TYPO3 Flow)
  • VlibTemplate
  • TinyButStrong
  • Contemplate
  • ETS (Easy Template System )
  • T24 - PHP template parser
  • HTML_Template_IT: Integrated HTML templates, PEAR PackageuBook template
  • UBook template
  • KTemplate
  • Hyperkit PHP / XML template engine
  • Beilpuz
  • Separate


To use a template engine, you need the template file (in which the output level data are included) as well as the script that loads the template and populates the placeholders with values.

The template might look like this:


Hi, {name } And so could a value assignment look from the script:

$ template -> assign ('name ', ' William Smith '); The result:


Hello, William Smith Template engines for Perl

  • Template Toolkit
  • Contemplate (including ASP)
  • Embperl
  • Mason
  • HTML template
  • Text Template

Template engines for Python

Example of use

# - * - Coding: utf -8 - * - # Module template needs to be imported from string import Template # Open for reading template, passing in content and close file template = open (' template.txt ', ' r') vorl_inhalt = () vorlage.close () # Treat the contents as a template template = Template ( vorl_inhalt ) # Define replacements in the following way replacements = {' name': ' Hans Meier ', ' street ': ' Str. 69 ',' Location ': '12345 Foobarhausen '} # Do replacements replace = template.substitute ( replacements ) # Write operation on file outfile = open (' output.txt ', ' w' ) outfile.write ( replace ) outfile.close () template.txt:

Name: Hans Meier Address: Str. 69 Location: 12345 Foobarhausen Template engines for C and C

For C and C there are several template engines, such as

  • Clear Silver The template engine Orkut and Yahoo Groups (set its own Branch a ).
  • Grantlee template system
  • Google ctemplate

Template engines for Java

Some template engines for Java is Java-based template engines, which are available under an open source license.

For more information about template engines

Other template engines are sometimes java -based.

  • Hamlet - Java-based template engine
  • Action4JAVA - Java -based framework with template core.
  • Jade4j - Java -based, free implementation of the Jade template engine
  • XSLTengine - Java-based template engine, in particular for web developers
  • Xpand - Java-based template engine for code generation
  • ASP
  • CTPP, Cross Platform template engine for C , C, PERL and PHP
  • GvTags template engine for Groovy
  • JQote2 - jQuery JavaScript Templating Engine
  • FilesFromCSV -. NET based - created for each CSV record a document