[Twisted-web] Nevow Templating question
Stephen Thorne
stephen at thorne.id.au
Mon Apr 12 22:49:43 MDT 2004
On Tue, Apr 13, 2004 at 12:43:09AM -0400, jonathan vanasco wrote:
>
> This works, but I think the approach might be wrong.
> (the output is what I want it to be, but I think I may have implemented
> things counter to the way nevow was designed)
>
> Can someone please offer their input?
Sure, see comments inline with code. Please bear in mind I haven't
executed this code, I'm just making it up ;)
> template.html
> -------------------
> <tr>
> <td valign="top"> pick a city</td>
> <td>
> <select name="city">
> <span nevow:data="citiesList" nevow:render="city"></span>
> </select>
<select name="city" nevow:data="citiesList" nevow:render="city" />
> </td>
> </tr>
>
>
> testing.py
> -------------------
> def data_citiesList(self, context, data):
> return {"New York":'1', "Los Angeles":'2'}
> def render_city(self, context, data):
> """Example of using stan to render a page.
> """
> return rend.stan(
> [
> T.option(value=v)[k] for (k,v) in
> data.items()
> ]
> )
return context.tag[
[ T.option(value=v)[k] for (k,v) in data.items() ]
]
>
> Output.html
> ----------------
> <tr>
> <td valign="top"> pick a city</td>
> <td>
> <select name="city">
> <option value=1>New York</option>
> <option value=2>Los Angeles</option>
> </select>
> </td>
> </tr>
Regards,
Stephen Thorne
More information about the Twisted-web
mailing list