[Twisted-web] nevow substitute into html attributes?

Samuel Reynolds sam at SpinwardStars.com
Fri Jul 9 08:30:20 MDT 2004

At 2004-07-08 04:12 PM -0700, you wrote:
>Nevow slots seem to be limited to replacing whole elements.  Is there any 
>way to have a slot which is an attribute or a value of an attribute?
>For one example, I want to render a list of mappings that looks like this:
>    list_of_links = [
>        { 'linkTitle': 'Big Fun Site', 'linkURL':
>    'http://bigfunsite.com/funfunfun/index.html'},
>        { 'linkTitle': 'Not Quite As Much Fun Site', 'linkURL':
>    'http://mediocre.com/its_ok.html'},
>        ]
>So I need an html template:
>        <ul nevow:data="list_of_links" nevow:render="sequence">
>            <li nevow:pattern="item" nevow:render="mapping">
>                <a href="???"><nevow:slot name="linkTitle">Link
>    Title</nevow:slot></a>
>            </li>
>        </ul>
>So the link title is taken care of but what do I put instead of '???' to 
>get the href to contain the value of linkURL for the item?

This works for me, and no attr or slots required:

<a nevow:pattern="item" nevow:render='link' />

def render_link(self, context, data):
     # Assume data is a list or tuple of (url,label)
     tag = context.tag.clear()
     tag.attributes['href'] = data[0]
     tag[ data[1] ]
     return tag

And make list_of_links return a list of (url,label) tuples.
Maybe not quite "the nevow way," but it works, and the
template is much cleaner (IMO).

- 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