Everyone, I'm somewhat new to Nevow and have a simple question - btw, it maybe already possible and i missed the man page... We mostly use HTML based templates to drive our presentations as we have an html designer that can design and maintain a large majority of the UI without knowledge of any coding. The designer delivers html that can be rendered on its own for review but also adds in directives, patterns and slots to make the programmers life easier. My question centers around the best way to have nested templates - that is i'd like a directive that would function as an include and all the appropriate Nevow render code get executed automatically. That way our designer can build a header, footer, sidebars, and other html components as separate files and the main template just "includes" as appropriate. Something like <nevow:include name="blah.html"> Additionally, and here is my Nevow ignorance, there must be a simple few lines of code that does the equivalent in code for example if i had: <nevow:render name = templateName> then in... def render_templateName(self, context, data): #load and render file templateName as include and return result Lastly, if the above method works OK then I'd rather have <nevow:render name=include nevow:arg=templateName> where i can have a generic include render method and take an argument from the html tag. So, like i said, being new this maybe all be easy/possible and i just missed it. Also, i've felt the wrath of mvc and proper separation of code from html for almost 10 years now and i understand how the above is in violation ;-) Thanks in advance for any help. Cheers, e.
Render methods can return rend.Page's. so def render_nested(self, context, data): return Mypage() If you want to pass data then just do <nevow:data="whatever" nevow:render="nested"/> Then define data_whatever to put some data on the stack and render_whatever to take the data and pass it ot yoru page constructor Erik Swan wrote:
Everyone,
I'm somewhat new to Nevow and have a simple question - btw, it maybe already possible and i missed the man page...
We mostly use HTML based templates to drive our presentations as we have an html designer that can design and maintain a large majority of the UI without knowledge of any coding. The designer delivers html that can be rendered on its own for review but also adds in directives, patterns and slots to make the programmers life easier.
My question centers around the best way to have nested templates - that is i'd like a directive that would function as an include and all the appropriate Nevow render code get executed automatically. That way our designer can build a header, footer, sidebars, and other html components as separate files and the main template just "includes" as appropriate. Something like <nevow:include name="blah.html">
Additionally, and here is my Nevow ignorance, there must be a simple few lines of code that does the equivalent in code for example if i had: <nevow:render name = templateName>
then in... def render_templateName(self, context, data): #load and render file templateName as include and return result
Lastly, if the above method works OK then I'd rather have <nevow:render name=include nevow:arg=templateName> where i can have a generic include render method and take an argument from the html tag.
So, like i said, being new this maybe all be easy/possible and i just missed it. Also, i've felt the wrath of mvc and proper separation of code from html for almost 10 years now and i understand how the above is in violation ;-)
Thanks in advance for any help. Cheers, e.
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
On Thu, 04 Nov 2004 13:33:10 -0800, Erik Swan <erik@splunktechnology.com> wrote:
Everyone,
I'm somewhat new to Nevow and have a simple question - btw, it maybe already possible and i missed the man page...
Actually... Even a poor man page would be welcome these days :)
My question centers around the best way to have nested templates - that is i'd like a directive that would function as an include and all the appropriate Nevow render code get executed automatically. That way our designer can build a header, footer, sidebars, and other html components as separate files and the main template just "includes" as appropriate. Something like <nevow:include name="blah.html">
Nevow provides Fragments that are mostly like Page objects but could be rendered inside another Page like they were simple tags or strings (that fill slots). <nevow:invisible nevow:render="content"> <nevow:slot name="content" /> </nevow:invisible> And in the code side: def render_content(self, ctx, data): ctx.tag.fillSlots('content', MyFragment()) return ctx.tag class MyFragment(rend.Fragment): docFactory = loaders.xmlfile('some_partial_html.html', ignoreDocType=True) I also suggest putting all the html from the partial html inside a <nevow:invisible> tag. I've implemented such a thing in weever: http://svn.berlios.de/viewcvs/weever/trunk/src/?rev=55#dirlist Here is the source view from svn, in the templates directory you will find all the templates while under web all the logic that handles the composition (main.py is the most important file) HTH -- Valentino Volonghi aka Dialtone Now running FreeBSD 5.3-beta6 Blog: http://vvolonghi.blogspot.com Home Page: http://xoomer.virgilio.it/dialtone/
On Thu, 2004-11-04 at 13:33 -0800, Erik Swan wrote:
Everyone,
I'm somewhat new to Nevow and have a simple question - btw, it maybe already possible and i missed the man page...
We mostly use HTML based templates to drive our presentations as we have an html designer that can design and maintain a large majority of the UI without knowledge of any coding. The designer delivers html that can be rendered on its own for review but also adds in directives, patterns and slots to make the programmers life easier.
My question centers around the best way to have nested templates - that is i'd like a directive that would function as an include and all the appropriate Nevow render code get executed automatically. That way our designer can build a header, footer, sidebars, and other html components as separate files and the main template just "includes" as appropriate. Something like <nevow:include name="blah.html">
WARNING: Experimental code alert. Use at your own risk. ;-) This sounds like you want macros. There is a relatively simple implementation in my sandbox ... svn co svn://divmod.org/svn/Nevow/sandbox/mg/macro The basic idea is that you have one (or more) XHTML files containing the macros. The page templates include a macro by adding a n:render="macro myMacro" attribute to some element. Macros are located, via the LocateMacroMixin, as macro_* attributes of the page (or more likely, some base page class). The macro_* attributes can use anything (stan, xmlfile, whatever) to load and return the template for the macro. The interesting bit of all this is that any pattern inside the page's macro-including element are pushed into the macro using fillSlots. Take a look at how page.html specifies the <title> for the 'head' macro or how the content is passed to the 'body' macro and you'll see what I mean. I've been using this technique for a while now and it works fairly well. Whether it fits your needs I'm not sure but any feedback/improvements would be gratefully accepted. Note: I know this implementation can be improved, i.e. perhaps an explicit n:macro tag to make things clearer and optional macro expansion at precompile time.
Additionally, and here is my Nevow ignorance, there must be a simple few lines of code that does the equivalent in code for example if i had: <nevow:render name = templateName>
then in... def render_templateName(self, context, data): #load and render file templateName as include and return result
Lastly, if the above method works OK then I'd rather have <nevow:render name=include nevow:arg=templateName> where i can have a generic include render method and take an argument from the html tag.
This is already possible using a parameterised renderer. In fact, the macro renderer described above does exactly this. See the render_macro function in macro.py. Hope this helps. Cheers, Matt
participants (4)
-
Erik Swan
-
Matt Goodall
-
orbitz
-
Valentino Volonghi