[Twisted-web] Slot/pattern/key changes

James Y Knight twisted-web@twistedmatrix.com
Wed, 11 Feb 2004 17:02:46 -0500


On Feb 11, 2004, at 4:32 AM, Matt Goodall wrote:
> It looks like this should be possible using something like this:
>
> HTML:
> <nevow:slot name="email"/><a pattern="email" href="#"
> class="whatever">name</a>
>
> Rendered by:
> context.fillSlots(
>     'email',
>     context.onePattern('email')(href=['mailto:a@bc.com'])['Mr X']
> )
>
> Although James's patch needs a couple of small changes to make that
> work.

If you're writing stan tree, this will work:
a(href=slot('emailhref'), class='whatever')[slot('email')]

Rendered by
context.fillSlots('email', 'Mr X')
context.fillSlots('emailhref', 'mailto:a@bc.com')

Or perhaps something like this:
def combineslot(context, data):
   newtag = context.locateSlotData('email')
   return context.tag(**newtag.attributes)[newtag.children]

a(renderer=combineslot('email'), class='whatever')
Rendered by:
context.fillSlots('email',invisible(href='mailto:a@bc.com')['Mr X']))

TBD: How to fit that into HTML Template syntax. Both those actually 
seem cleaner, to me, than the alternative above.

James