[Twisted-web] Use nevow:pattern and nevow:attr to render a list of

Phil Mayers p.mayers at imperial.ac.uk
Fri Jul 6 06:22:11 EDT 2007


On Fri, 2007-07-06 at 11:15 +0200, Daniel de la Cuesta wrote:
> Following your instructions I have done:
> 
>   <select>
>     <div nevow:render="formats">
>       <option nevow:pattern="option">
>         <nevow:attr name="value"><nevow:slot
> name="value" /></nevow:attr>
>         <nevow:slot name="label" />
>       </option>
>     </div>
>   </select>
> 
> On the other side I have:
> 
>     def render_formats(self, ctx, data):         
> 
>         for k,v in mydict.iteritems():
>             pattern.fillSlots('value', v).fillSlots('label', k)
> 
> But I cannot acces the pattern variable, what am I doing wrong?


do this:

the_div = ctx.tag

# when called, this will return option tags
option_generator = the_div.patternGenerator('option')

for k,v in mydict.items():
    # man an option tag
    an_option = option_generator()
    # set the variables
    an_option.fillSlots('value', v).fillSlots('label', k)
    # put it inside the div
    the_div[an_option]

return the_div

HTH




More information about the Twisted-web mailing list