[Twisted-web] Alternative to <nevow:attr>

Samuel Reynolds sam at SpinwardStars.com
Tue Oct 19 07:36:06 MDT 2004


At 2004-10-19 12:42 AM -0700, you wrote:
>Ok, so currently if you want dynamic stuff to happen in an attribute you
>have to do something along the lines of this.
>
><a render="mylink">
>     <nevow:attr name="href">
>         <nevow:slot name="link" />
>     </nevow:attr>
>     <nevow:slot name="label" />
></a>
>
>def render_mylink(self, ctx, data):
>         ctx.fillSlots('link', data[0])
>         ctx.fillSlots('label', data[1])
>
>         return ctx.tag
>
>Which is horrendously ugly and difficult to explain to pretty much
>anyone.  Now, there are plenty of other solutions to this problem, but
>none of them provide the flexability for the template author as
><nevow:attr> and <nevow:slot> do.

I haven't started using nevow:attr yet. I've done some
straightforward string substitutions. Anathema to the
Twisted Way, I suspect, but it works.

An example from a working application:

[In TEMPLATE]
<a href='/daily/%s' nevow:data='today'
     nevow:render='interpolateHref'>Today</a>

[In Renderer]
def render_interpolateHref(self, context, data):
     """
     Interpolate data into href attribute of tag.

     Href attribute is assumed to contain a '%s' formatting spec.
     """
     tag = context.tag()
     href = tag.attributes['href']
     tag.attributes['href'] = href % str(data)
     return tag

FWIW.

- Sam

__________________________________________________________
Spinward Stars, LLC                        Samuel Reynolds
Software Consulting and Development           303-805-1446
http://SpinwardStars.com/            sam at SpinwardStars.com 





More information about the Twisted-web mailing list