Jinja (Template engine)
Encyclopedia
Jinja is a template engine
Template engine
A 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.-Types:...

 for the Python programming language
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...

. It is similar to the Django template engine but provides Python-like expressions while ensuring that the templates are evaluated in a sandbox
Sandbox (computer security)
In computer security, a sandbox is a security mechanism for separating running programs. It is often used to execute untested code, or untrusted programs from unverified third-parties, suppliers, untrusted users and untrusted websites....

. It's a text-based template language and thus can be used to generate any markup as well as sourcecode. It's licensed under a BSD License
BSD licenses
BSD licenses are a family of permissive free software licenses. The original license was used for the Berkeley Software Distribution , a Unix-like operating system after which it is named....

.

The Jinja template engine allows customization of tagshttp://jinja.pocoo.org/2/documentation/extensions#module-jinja2.ext, filters, tests, and globalshttp://jinja.pocoo.org/2/documentation/extensions#expression-statement. Also, unlike the Django template engine, Jinja allows the template designer to call functions with arguments on objects.

Jinja, like Smarty
Smarty
Smarty is a web template system written in PHP. Smarty is primarily promoted as a tool for separation of concerns.Smarty is intended to simplify compartmentalization, allowing the presentation of a web page to change separately from the back-end...

, also ships with an easy-to-use filter system similar to the Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 pipeline
Pipeline (Unix)
In Unix-like computer operating systems , a pipeline is the original software pipeline: a set of processes chained by their standard streams, so that the output of each process feeds directly as input to the next one. Each connection is implemented by an anonymous pipe...

.

Example

Here is a small example of a template:

from jinja import from_string

tmpl = from_string(u\



{% for item in item_list %}
{% if not loop.last %},{% endif %}
{% endfor %}

)

print tmpl.render(
variable='Value with data',
item_list=[1, 2, 3, 4, 5, 6]
)
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK