    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("""\
      ...
... ... Who are you, ${foo}? ...
... I will be replaced ...
... ...
    """)

      >>> content = PageTemplate("""\
      ...
...
... ... I replace you: ${foo} (${bar}). ... ...
...
""") >>> print content(main=main, bar='bar')
Who are you, foo?
I replace you: foo (boo).
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): ... RuntimeError: Caught exception rendering template. ... TypeError: range expected at least 1 arguments, got 0 Exception while evaluating definition: >>> PageTemplate("""\ ...
... ...
""").render() Traceback (most recent call last): ... RuntimeError: Caught exception rendering template. ... TypeError: range expected at least 1 arguments, got 0 Exception while evaluating interpolation: >>> PageTemplate("""\ ...
... ${range()} ...
""").render() Traceback (most recent call last): ... RuntimeError: Caught exception rendering template. ... TypeError: range expected at least 1 arguments, got 0