zope.pagetemplate

Software Screenshot:
zope.pagetemplate
Software Details:
Version: 4.0.0
Upload Date: 11 May 15
Distribution Type: Freeware
Downloads: 5

Rating: nan/5 (Total Votes: 0)

zope.pagetemplate is a module that provides an elegant templating mechanism that achieves a clean separation of presentation and application logic while allowing for designers to work with templates in their visual editing tools (FrontPage, Dreamweaver, GoLive, etc.).

Detailed Documentation

ZPT (Zope Page-Template) Architecture

There are a number of major components that make up the page-template architecture:

- The TAL compiler and interpreter. This is responsible for compiling source files and for executing compiled templates. See the zope.tal package for more information.

- An expression engine is responsible for compiling expressions and for creating expression execution contexts. It is common for applications to override expression engines to provide custom expression support or to change the way expressions are implemented. The zope.app.pagetemplate package uses this to implement trusted and untrusted evaluation; a different engine is used for each, with different implementations of the same type of expressions.

- Expression contexts support execution of expressions and provide APIs for setting up variable scopes and setting variables. The expression contexts are passed to the TAL interpreter at execution time.

- The most commonly used expression implementation is that found in zope.tales.

- Page templates tie everything together. They assemble an expression engine with the TAL interpreter and orchestrate management of source and compiled template data. See zope.pagetemplate.interfaces.

Page Templates

Introduction

Page Templates provide an elegant templating mechanism that achieves a clean separation of presentation and application logic while allowing for designers to work with templates in their visual editing tools (FrontPage, Dreamweaver, GoLive, etc.).

This document focuses on usage of Page Templates outside of a Zope context, it does not explain how to write page templates as there are several resources on the web which do so.

Simple Usage

Using Page Templates outside of Zope3 is very easy and straight forward. A quick example:

>>> from zope.pagetemplate.pagetemplatefile import PageTemplateFile
>>> my_pt = PageTemplateFile('hello_world.pt')
>>> my_pt()
u'< html >< body >Hello World< /body >< /html >'


Subclassing PageTemplates

Lets say we want to alter page templates such that keyword arguments appear as top level items in the namespace. We can subclass PageTemplate and alter the default behavior of pt_getContext() to add them in:

from zope.pagetemplate.pagetemplate import PageTemplate

class mypt(PageTemplate):
 def pt_getContext(self, args=(), options={}, **kw):
 rval = PageTemplate.pt_getContext(self, args=args)
 options.update(rval)
 return options

class foo:
 def getContents(self): return 'hi'


So now we can bind objects in a more arbitrary fashion, like the following:

template = """
< html >
< body >
< b tal:replace="das_object/getContents" >Good Stuff Here< /b >
< /body >
< /html >
"""

pt = mypt()
pt.write(template)
pt(das_object=foo())


See interfaces.py.

What is new in this release:

  • Replaced deprecated zope.interface.classProvides usage with equivalent zope.interface.provider decorator.
  • Replaced deprecated zope.interface.implements usage with equivalent zope.interface.implementer decorator.
  • Dropped support for Python 2.4 and 2.5.
  • PageTemplate.pt_render() has a new argument, check_macro_expansion, defaulting to True.
  • PageTemplateTracebackSupplement passes check_macro_expansion=False, to avoid LP#732972.

What is new in version 3.6.3:

  • Fixed test assertions to be compatible with zope.tal 3.6.

What is new in version 3.6.1:

  • Fixed issue with missing default value for strictinsert.

What is new in version 3.6.0:

  • Replaced StringIO stream class with a faster list-based implementation.
  • Abstract out the template engine and program interfaces and allow implementation replacement via a utility registration.
  • Removed ancient copyright from test files (LP: #607228)

Requirements:

  • Python

Other Software of Developer Zope Corporation and Contributors

Comments to zope.pagetemplate

Comments not found
Add Comment
Turn on images!