[Zope3-checkins]
SVN: Zope3/branches/ZopeX3-3.0/src/zope/pagetemplate/readme.txt
Merged from trunk 25970:
Jim Fulton
jim at zope.com
Fri Jul 2 16:45:05 EDT 2004
Log message for revision 26068:
Merged from trunk 25970:
Updated to reflect reality (perhaps).
Also, rely on DEPENDENCIES.cfg and interfaces.py for more
documentation.
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/pagetemplate/readme.txt
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/pagetemplate/readme.txt 2004-07-02 20:38:20 UTC (rev 26067)
+++ Zope3/branches/ZopeX3-3.0/src/zope/pagetemplate/readme.txt 2004-07-02 20:45:05 UTC (rev 26068)
@@ -1,89 +1,64 @@
+==============
Page Templates
+==============
- Introduction
+:Author: Kapil Thangavelu <hazmat at objectrealms.net>
- 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.).
+Introduction
+------------
- 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.
+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.).
- Dependencies
+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.
- Zope3 Package Dependencies
+Simple Usage
+------------
- - zope.tal (Template Attribute Language)
+Using Page Templates outside of Zope3 is very easy and straight
+forward. A quick example::
- - zope.talInterface
+ >>> from zope.pagetemplate.pagetemplatefile import PageTemplateFile
+ >>> my_pt = PageTemplateFile('hello_world.pt')
+ >>> my_pt()
+ u'<html><body>Hello World</body></html>'
- - ZTUtils (batching utilities for zpt)
+Subclassing PageTemplates
+-------------------------
- - The standard logging package ("logging") from Python 2.3.
+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::
- Simple Usage
+ from zope.pagetemplate.pagetemplate import PageTemplate
- Using PageTemplates outside of Zope3 is very easy and straight
- forward. a quick example::
+ class mypt(PageTemplate):
+ def pt_getContext(self, args=(), options={}, **kw):
+ rval = PageTemplate.pt_getContext(self, args=args)
+ options.update(rval)
+ return options
- >>> from zope.pagetemplate.pagetemplatefile import PageTemplateFile
- >>> my_pt = PageTemplateFile('hello_world.pt')
- >>> my_pt()
- u'<html><body>Hello World</body></html>'
+ class foo:
+ def getContents(self): return 'hi'
- Setting Up Contexts
+So now we can bind objects in a more arbitrary fashion, like the
+following::
- Rendering a page template without binding data to is not very
- interesting. By default keyword arguments you pass in page
- templates appear in the options namespace.
+ template = """
+ <html>
+ <body>
+ <b tal:replace="das_object/getContents">Good Stuff Here</b>
+ </body>
+ </html>
+ """
- pt_getContext(**keywords)
- Should ignore keyword arguments that it doesn't care about,
- and construct the namespace passed to the TALES expression
- engine. This method is free to use the keyword arguments it
- receives.
+ pt = mypt()
+ pt.write(template)
+ pt(das_object=foo())
- pt_render(namespace, source=0)
- Responsible the TAL interpreter to perform the rendering. The
- namespace argument is a mapping which defines the top-level
- namespaces passed to the TALES expression engine.
-
- Narrative (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 page template 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())
-
- Author
-
- Kapil Thangavelu <hazmat at objectrealms.net>
+See interfaces.py.
More information about the Zope3-Checkins
mailing list