[Twisted-Python] WOVEN Question
Hi all I have a question : I want to create a business platform using Woven. Like Zope (ZPT), I saw woven is separating logic/presentation (and control, yes, woven is based on MVC). But In zope, I can define some macros that could expand when I want. I mean, if I have a site like this +--------------------+ | Menu1 menu2 ----- | | | | | | some text | | | +--------------------+ and want an "include" of the menu in several pages. Should I use a new view ? It would be weird since I would have some large pieces of HTML in python code. Any suggestion ? -- Philippe Lafoucrière <lafou@wanadoo.fr> InFuzzion
On 23 Jun 2003 11:01:27 +0200 Philippe Lafoucrière <lafou@wanadoo.fr> wrote:
I have a question : I want to create a business platform using Woven. Like Zope (ZPT), I saw woven is separating logic/presentation (and control, yes, woven is based on MVC). But In zope, I can define some macros that could expand when I want. I mean, if I have a site like this
Woven has macros that are essentially identical to ZPT METAL macros - see twisted.web.widgets.ExpandMacro. -- Itamar Shtull-Trauring http://itamarst.org/ http://www.zoteca.com -- Python & Twisted consulting
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. -- Alex Levy WWW: http://mesozoic.geecs.org "Never let your sense of morals prevent you from doing what is right." -- Salvor Hardin, Isaac Asimov's _Foundation_
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
On Mon, Jun 23, 2003 at 05:59:11PM +0200, Philippe Lafoucri?re wrote:
Hope most of the woven Magic will be explained in 1.0.6 doc ! I definitly want to try it now ...
I'm pretty sure the Woven docs haven't been touched significantly since 1.0.5 (except for some minor reformatting?) -- thanks to the persistence of Andrew Dalke, you can find the current build of the howtos from CVS here: http://twistedmatrix.com/users/warner/doc-latest/ If you find expandMacro, or anything else, isn't covered... documentation patches would be very gratefully accepted! :) -Andrew.
http://twistedmatrix.com/users/warner/doc-latest/
If you find expandMacro, or anything else, isn't covered... documentation patches would be very gratefully accepted! :)
thank you very much. Hmm, the woven part hasn't been touched, yes. I can't help to write some help now (don't have enough time), but maybe later (next month) Philippe
participants (4)
-
Alex Levy
-
Andrew Bennetts
-
Itamar Shtull-Trauring
-
Philippe Lafoucrière