Standalone ZPT?

Richie Hindle richie at entrian.com
Wed Aug 21 04:40:52 EDT 2002


Gerhard,

> Are there any other Python templating systems that work like ZPT (i. e.
> use attributes instead of custom tags)?

You could look at PyMeld, my very lightweight HTML manipulation module:

>>> import PyMeld
>>> html = '''<html><body>
... <textarea id='message' rows='2' cols='50'>Enter a message here.</textarea>
... </body></html>'''
 
>>> page = PyMeld.Container( html )       # Create a Container from the HTML.
>>> page.message.content = "New message." # Change the content of a tag.
>>> page.message.rows = 10                # Change an attribute value.
>>> print page
<html><body>
<textarea id='message' rows='10' cols='50'>New message.</textarea>
</body></html>

PyMeld also lets you programatically create clones of pieces of HTML,
manipulate them programatically, and insert them back into your document;
there's an example on the web page of taking a table populated with one
row of dummy data and populating it with several rows of real data.

PyMeld has no special requirements for the HTML, other than that each
tag you want to manipulate must have an 'id' attribute, and the attribute
values must be quoted.  It works by string substitution rather than by
parsing and rebuilding the document, so it's immune to invalid or
incomplete HTML, as long as the pieces you want to manipulate make sense.

See http://www.entrian.com/PyMeld/ for examples, documentation and
download.  (I have a new version that allows deletion of tags and
attributes, which I'll be publishing soon - let me know if you need
it.)

-- 
Richie Hindle



More information about the Python-list mailing list