Template classes ================ The ``chameleon.zpt`` package provides the ``PageTemplate`` and ``PageTemplateFile`` classes which allow easy usage of templates in your application. Usage ----- >>> from chameleon.zpt.template import PageTemplate >>> print PageTemplate("""\ ...
... Hello World! ...
""")()
Hello World!
>>> from chameleon.zpt.template import PageTemplateFile >>> from chameleon.zpt import tests >>> path = tests.__path__[0] >>> t = PageTemplateFile(path+'/helloworld.pt') >>> print t()
Hello World!
>>> import os >>> t.filename.startswith(os.sep) True METAL template integration -------------------------- Page templates expose macros in their ``macros`` attribute. >>> main = PageTemplate("""\ ...
...
... I will be replaced ...
...
""") >>> content = PageTemplate("""\ ...
...
... I replace you. ...
...
""") >>> print content(main=main)
I replace you.
Error handling -------------- When an exception is raised which does not expose a bug in the TAL translation machinery, we expect the exception to contain the part of the template source that caused the exception. Exception while evaluating expression: >>> PageTemplate("""\ ...
... ...
""").render() Traceback (most recent call last): ... TypeError: range expected at least 1 arguments, got 0 Exception while evaluating definition: >>> PageTemplate("""\ ...
... ...
""").render() Traceback (most recent call last): ... TypeError: range expected at least 1 arguments, got 0 Exception while evaluating interpolation: >>> PageTemplate("""\ ...
... ${range()} ...
""").render() Traceback (most recent call last): ... TypeError: range expected at least 1 arguments, got 0