ANN: CherryTemplate-1.0.0 released
Hello everyone, I'm happy to announce the first release of CherryTemplate, an easy and powerful templating system in python. Note that it is not "yet another templating system" because it used to be part of CherryPy, but is now released as a standalone package. Basically, you use it like this: $ python Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
from cherrytemplate import renderTemplate name = "world" renderTemplate('Hello, <py-eval="name"/>') 'Hello, world'
The language only has a few tags: py-eval, py-exec, py-code, py-if, py-for, py-include but it is quite powerful because most of python's power is still available from the template: - "py-for" allows you to do things like <py-for="i,j in [(0,0), (1,2), (3,1)]"> - "py-code" allows you to insert full blocks of pure python code inside your template (it takes care of the indentation for you) CherryTemplate can also render external templates (ex: renderTemplate(file = 'template.html')) and has full unicode support. Once nice feature about it is that is uses generators to render your template, so if you need to process a large amount of data you can tell it to return a generator, and then you can loop through it. This way it doesn't use up too much memory. Here is an example:
template = '''<py-for="i in range(5)">i:<py-eval="str(i)"/></py-for>''' result = renderTemplate(template, returnGenerator = True) for res in result: print repr(res) 'i:' '0' 'i:' '1' 'i:' '2' 'i:' '3' 'i:' '4'
You can find more information (including the download link) on this page: http://trac.cherrypy.org/cgi-bin/trac.cgi/wiki/CherryTemplate Remi.
participants (1)
-
remi@cherrypy.org