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

David Reid dreid at dreid.org
Tue Oct 19 01:42:46 MDT 2004

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:slot name="label" />

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.

For instance:
   <nevow:attr name="href">
        /users/<nevow:slot name="username" />/images
   </ nevow:attr>

Works perfectly well.  Which according to fzZzy is the main reason for
choosing this syntax.

A comparison to this with the syntax of TAL was recently mentioned on
the ML (Comparison with ZPT [Was: [Twisted-web] Sub-tag level templating
in Nevow: possible?]), and the TAL syntax seems to be cleaner, though
I'm not sure if it provides the above functionality.  While discussing
it on IRC I came to a conclusion that the following would be
comfortable, and flexible syntax alternative (not replacement) for

<a href="/images/archives/%(year)/%(month)/%(day)"
nevow:attributes="href=year,month,day alt=label">
    <nevow:slot name="label" />

basically when the template was getting parsed, the Tag instance would
end up something like this.
Tag(name='a', attributes={'href': 
	['/images/archives/', slot(name='year'), slot(name='month'),

It provides the flexibility, and in my opinion is just a little more
intuitive than <nevow:attr>.

-------------- 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://twistedmatrix.com/pipermail/twisted-web/attachments/20041019/addeb3cd/attachment.bin

More information about the Twisted-web mailing list