Quixote and SimpleTAL Integration
Note: this solution is written for Quixote 1.x. The basic idea should still work for Quixote 2 however.
Here's quixote_tal.py a module that demonstrates using SimpleTAL with Quixote.
It has two interesting features:
- Access to quixote objects via paths, e.g.
<p tal:content="root/package/obj/method">results of calling method</p>
- This lets you use path expressions to locate and call quixote objects in exactly the same way as using normal Quixote URLs.
- Page templates as methods, allowing access to instances via the self variable. e.g.
<p tal:content="self/method">results of calling instance method</p>
- This lets you create a series of templates in a class to display instances.
You can also access normal quixote stuff like the request, form, cookies, session, user, etc.
Other examples of using SimpleTAL:
Usage
To use quixote_tal simply create templates in your quixote application. Here's an example:
from quixote_tal import Template, TemplateMethod from new import instancemethod _q_exports=['page', 'bill'] # creates a stand alone web page page=Template('/path/to/page.html') class Person: """ Example class that uses a template to display instances """ _q_exports=['name'] def __init__(self, name): self.name=name _q_index=TemplateMethod('/path/to/person.html') bill=Person("Bill")
Here's an example of what the person.html template might contain:
<html> <h1>Person</h1> <p>My name is <b tal:replace="self/name">name</b></p> </html>
Here's an example of a stand alone webpage such as page.html:
<html> <p>Quixote root name <b tal:content="python:root.__name__">name</b></p> <p>URL <b tal:content="request/get_url">url</b></p> <p>Form variables</p> <ul> <li tal:repeat="name request/form/keys" tal:content="name">name</li> </ul> <p>bill's name <b tal:replace="root/bill/name">name</b></p> </html>
Note: in the example above a python expression is required to access root.name since it isn't a web accessible object. Python expressions aren't security restricted in simpletal like they are in ZPT.
---