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

Andrew Bennetts andrew-twisted at puzzling.org
Tue Oct 19 15:06:11 MDT 2004


On Tue, Oct 19, 2004 at 12:10:37PM -0700, David Reid wrote:
> On Tue, 2004-10-19 at 02:51, Andrew Bennetts wrote: 
> > TAL does allow this, in two ways (that I know of):
> > 
> > First, there's the hackish way:
> 
> They're both hackish ways in my opinion, and the latter
> Another alternative is for the alternative syntax to not even support
> such behavior, and only be for the general case which would look
> something like this:
> 
> <a nevow:attributes="href=link alt=label"><nevow:slot name="label"
> /></a>
> 
> (Looks an aweful lot like mg's attr.tac example, doesn't it?)

Firstly, I really don't know Nevow, I just lurk on the discussions about it.
I mention ZPT from time-to-time mainly out of selfishness: it would be
easier for me to learn Nevow if it were more like ZPT ;)

Now, on to the reply...

mg's attr.tac has this in the template:

    <ul nevow:data="links" nevow:render="sequence">
      <li nevow:pattern="item" nevow:render="link"><a href="#" nevow:render="attribute href=link,alt=label"><nevow:slot name="label">label</nevow:slot></a></li>
    </ul>

I don't see what this does that is different to:

    <ul tal:repeat="linkinfo context/links">
      <li><a href="#" tal:attributes="href linkinfo/link; label linkinfo/label"/></li>
    </ul>

Although I don't totally understand why mg's attr.tac has a nevow:slot tag
for label and not link, as far as I can tell the ZPT I give here is
equivalent in concept.  Explanations and/or corrections welcome!

Of course, my ZPT examples requires that the code would require there to be
a linkinfo class, e.g.

    class LinkInfo:
        def __init__(self, link, label):
            self.link = link
            self.label = label

And context/links would just be a list of these.  I don't see this as being
any more complex than what attr.tac does, though.

If nothing else, I hope this discussion can serve as the basis for a "Nevow for
ZPT users" tutorial.

-Andrew.




More information about the Twisted-web mailing list