[Twisted-web] patch: default values for slots from html templates

Steven Armstrong sa at c-area.ch
Thu Mar 3 12:21:04 MST 2005

On 03/03/05 19:28, Sridhar Ratna wrote:
>> HTML:
>> <span><n:slot name="my_slot_name" default="Whatever" /></span>
> Shouldn't this be 
> <span><n:slot name="my_slot_name">Whatever</n:slot></span>

That's not the same.

e.g: given a dict like:
people = [{'name': "Fred", 'surname': "Flintstone"}]

<div n:data="people" n:render="sequence">
  <div n:pattern="item" n:render="mapping">
    <n:slot name="name" />
    <n:slot name="surname" />
    <n:slot name="age">Not defined</n:slot> <-- This raises a KeyError
    <n:slot name="age" default="Not defined" /> <-- This doesn't

The cool thing about default="whatever" is that you can (mis)use it to
mark slots as optional.

IMHO it makes the render="mapping" functionality even more powerfull.

More information about the Twisted-web mailing list