Brevé is a template engine inspired heavily by Nevow Stan [1]. Unlike most Python template engines, Brevé is not an XML parser, rather Brevé templates are expressed as pure Python code with a single limitation: only expressions are allowed.
As to how Brevé compares with other template engines, see this comparison of Brevé and Myghty for a side-by-side comparison using a small web application.
You can also see how Brevé compares performance-wise against a variety of other template engines.
No. While heavily influenced and inspired by Stan, Brevé is a ground-up rewrite with a different focus and feature-set. Simple Stan and Brevé expressions are pretty much compatible, but the advanced features of each are absent from the other or have an incompatible syntax.
In general, Stan is intended for generating XML fragments from within a Python program whereas Brevé is intended to generate complete documents from outside the main program.
include and inherits are not tags. They are directives that must be used from within a Template object. Because renderers don't execute within the template's namespace, they aren't available.
The HTML output by Brevé has the minimal amount of whitespace required to make it syntactically correct. This is an optimization for both Brevé and the web browser. Unfortunately it also makes the output hard to read when debugging a page. You can address this by installing the Python tidy library [2] and enabling it in Brevé:
from breve import Template
Template.tidy = True
It's recommended to turn this option off for production environments due to the overhead incurred.
You should always instantiate a new Template object for each render. They aren't intended to be reused.
Use the html4 tags included with Brevé. You can do this by selecting them when you instantiate the Template object:
from breve import Template
from breve.tags.html4 import tags
t = Template ( tags )
or you can select them at render-time via the format argument to render():
from breve import Template
from breve.tags.html import tags
t = Template ( tags )
t.render ( 'mytemplate', format = 'html4' )
In general, the first method is preferred.
They are still there, just no longer documented. They were a mistake and will be removed with Brevé 2.0. You should use normal Python expressions instead.
Conversions: when ( condition ) -> test ( condition ) and ( block ) switch/case -> no equivalent: use multiple tests.
See the main documentation on conditionals for more discussion on using Python expressions as conditional expressions.
People are often confused because conditional tags (when, switch/case) don't short-circuit like regular Python conditionals. This can lead to unexpected side-effects if the conditional block contains an error (i.e. undeclared identifier) because the conditional block is always executed regardless of the result of the conditional. Only the output is suppressed. This is the reason conditional tags have been deprecated (see previous FAQ question).
Since Brevé is just a Python expression, names must be valid as Python variable names. This means you can't do something like:
meta ( http-equiv="refresh", content="15;url=http://www.google.com" )
as it will cause a syntax error. Instead you must pass it as a dictionary:
meta ( **{ 'http-equiv': "refresh", 'content': "15;url=http://www.google.com" } )
This problem also manifests itself around the del tag. You can't use this tag directly as Python considers it an operator.
Back to Main Documentation
| [1] | http://www.divmod.org/nevow |
| [2] | http://utidylib.berlios.de/ |