[Twisted-web] choosing between nodes

Alex Levy mesozoic at polynode.com
Sat Apr 10 17:08:14 MDT 2004

On Sat, 2004-04-10 at 18:27, Ellers wrote:
> <div id="content">
>  <span nevow:data="display" nevow:render="xml"/>
>  <span nevow:data="edit" nevow:render="xml">
>   <form>this is edit: more will go in here...</form>
>  </span>
>  <span nevow:data="save" nevow:render="xml/>
>   <p>you have saved: <span nevow:data="saved_data" nevow:render="xml/>
>  </span>
> </div>

First off, you don't want to be using span tags, you want to be using
div tags -- span tags aren't block elements, so they aren't supposed to
contain things like forms and paragraphs (as far as I understand).

Here's what you really want:

 <div nevow:render="display"></div>
 <div nevow:render="edit">
  <form nevow:render="edit_form"></form>
 <div nevow:render="save">
   You have saved: <span nevow:render="save_data"></span>

class MyPage:
    def render_display(self, ctx, data):
        if not show_display: return ctx.tag.clear()
        # More...

    def render_edit(self, ctx, data):
        if not show_edit: return ctx.tag.clear()
        # More...

    def render_save(self, ctx, data):
        if not show_save: return ctx.tag.clear()
        # More...

    # Implement other renderers (edit_form and save_data)...

There's nothing that says you have to use Nevow's predefined renderers;
for most complex rendering situations, you're going to want to write
your own render_* functions.

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_

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://pyramid.twistedmatrix.com/pipermail/twisted-web/attachments/20040410/cae0b9d6/attachment.bin

More information about the Twisted-web mailing list