Documentation - Python
Quick start
from domtempl import DOMtempl
Reading the template
l = DOMtempl('path/to/template.html')
or
l = DOMtempl('<html><p data-var="foo"></p></html>', DOMtempl.FRAGMENT);
Reading variables defined/expected by template
l = DOMtempl('<html><p data-var="foo">Boo</p></html>', DOMtempl.FRAGMENT); print l.vars #{'foo' : 'Boo'}
Writing variables
l.assign("foo", "Hello world")
You can also assign variables by accessing the vars
public property,
l.vars['foo'] = "Hello world"
has the same effect.
Writing output
l.out()
which is a shorthand for
html = l.dump() print html
Writing XML output
print l.dumpXML(); #or l.outXML()
Same as above, but produces XML instead of HTML.
Complete example
from domtempl import DOMtempl l = DOMtempl('<html><p data-var="animal">cat</p></html>', DOMtempl.FRAGMENT); print l.vars #{'animal' : 'cat'} l.assign("animal", "dog") l.out() #<html><p>dog</p></html>