Generic interface for Python template engines
Project description
collective.templateengines is an template language backend manager for Python. It defines generic Zope interfaces for communicating with various Python template engines to achieve higher code reuse value.
This package is still much in development. All contributions and comments are welcome.
Features
collective.templateengines helps you to achieve
Easy, pluggable, template language switching. Write special tag code only once and use it across all template engines.
Clean your codebase from template language dependencies.
Generic error and warning reporting mechanism across template engines.
Motivation
All template engines have their shortcomings. Sooner or later you want to try yet another engine, or someone else wants to use another template engine within your project. This package is aimed to make that transition as smooth as possible.
Features
egg deployment and easy install support from PyPi repository
Interfaces defined using standard Zope interfaces package
Backends for Django template Language, Cheetah and Jinja2
Unit tests
Installation
Install collective.templateengines egg
Install any of following template engine eggs: Django, Jinja2, Cheetah
Usage
Please take a look on collective.easytemplate package how to support switching between template engines and registering tags for them.
The following example shows how one can switch between Django and Cheetah template engines with one line of change. Naturally, the templates themselves need to be refactored.
Cheetah:
from collective.templateengines.backends import cheetah engine = cheetah.Engine() context = DictionaryContext({"foo":"bar"}) template, syntax_errors = engine.loadString("Show variable $foo", False) result, evaluation_errors = template.evaluate(context)
Django:
from collective.templateengines.backends import djangotemplates engine = djangotemplates.Engine() context = DictionaryContext({"foo":"bar"}) template, syntax_errors = engine.loadString("Show variable {{ foo }}", False) result, evaluation_errors = template.evaluate(context)
Problems
Cheetah architecture lacks separate exposed compiling and evaluating phases
Cheetah exposes the full Python namespace to templates by default, making it hard to secure it
Cheetah cannot traverse Zope functions or attributes
Examples
Python Template Engines is used in
Easy Template product for Plone.
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for collective.templateengines-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd58bbad08e6b9aa04b0018910f8472dc246d4a11b1a162ef7ce93cf5a1eee75 |
|
MD5 | 636a89ca8eb3edd6b91b51faf6e0c618 |
|
BLAKE2b-256 | 6158fa853764390d6ec00dd4626e9e30d1442cc53c00ad9ba9eb93824b488f1b |