[Twisted-Python] WOVEN Question
Philippe Lafoucrière
lafou at wanadoo.fr
Mon Jun 23 09:59:11 MDT 2003
On Mon, 2003-06-23 at 17:50, Alex Levy wrote:
> On Mon, Jun 23, 2003 at 11:01:27AM +0200, Philippe Lafoucri?re wrote:
> -- snip --
> > macros that could expand when I want
> -- snip --
>
> I was making the same complaint in #twisted a couple weeks ago, and was
> pointed to a wonderful piece of code: woven.widgets.ExpandMacro. Check it
> out; I've included a brief example below.
>
> I have a macro file:
>
> -- template.xhtml --
>
> <html>
> <head macro="head">
> <link rel="stylesheet" href="style.css"/>
> <title slot="title">Fill me</title>
> </head>
> <body macro="body">
> <h1>My site</h1>
> <div>Nav bar goes here</div>
> <div slot="content">Content</div>
> </body>
> </html>
>
> -- end --
>
> ...and then my Page does something like this:
>
> -- mypage.py --
>
> class MyPage(page.Page):
>
> template = """
> <html>
> <head view="headMacro">
> <title fill-slot="title">My title</title>
> </head>
> <body view="bodyMacro">
> <div fill-slot="content">Whatever</div>
> </body>
> </html>"""
>
> def wvfactory_headMacro(self, request, node, m):
> return widgets.ExpandMacro(m,
> macroFileDirectory = '/path/to/templates',
> macroFile = 'template.xhtml',
> macroName = 'head')
>
> def wvfactory_bodyMacro(self, request, node, m):
> return widgets.ExpandMacro(m,
> macroFileDirectory = '/path/to/templates',
> macroFile = 'template.xhtml',
> macroName = 'body')
>
> -- end --
>
> I really like this functionality, and I think it should be pointed out in
> the documentation. Dunno if that's already done for 1.0.6 docs, but the
> above code works with Twisted 1.0.5.
>
> Hope this helps.
A LOT :)
It's similar to what Itamar pointed in the API doc.
Hope most of the woven Magic will be explained in 1.0.6 doc !
I definitly want to try it now ...
BTW, thank you all
Philippe
More information about the Twisted-Python
mailing list