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

Stefano Debenedetti ste at demaledetti.net
Thu Mar 3 15:33:41 MST 2005


James Y Knight ha scritto:
> On Mar 3, 2005, at 3:40 PM, Tommi Virtanen wrote:
[..]
>> Also, I'd imagine it's a valid use case to want to see some "example
>> data" in the template, when viewed directly, and still set the default
>> to something else.
> 
> If that's a requirement, I don't think your proposed syntax will do it, 
> because the webmonkey will see both MISSING *and* John Doe. If that's 

That won't be a problem for the web monkey (see below for the reason why) but even if it was the web monkey would then promply do:

<p class="person">
   <n:slot name="fullname">
     <n:slotdefault style="display:none">MISSING</n:slotdefault>
     John Doe
   </n:slot>
</p>

which does the trick in Mozilla. Oh well, the web monkey doesn't love IE anyway.. ;-)

(it will work on IE too for text/xml content with an external CSS)

> not a requirement (and I personally don't think it needs to be, but as 
> I don't do much webmonkeying, could be convinced otherwise), a much 

It wouldn't be a problem anyway for the web monkey because it is usually a matter of text size, not of actual content: when the page is used as a mockup the actual text is usually some dummy string like "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam..." while the default text is usually something really short like "-" or "N/A" or "Nothing here sorry".

So even if the mockup text showed "N/ALorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam..." it would make no difference whatsoever (in most cases).

> simpler solution is to do <n:slot name="fullname" 
> allowDefault="true">MISSING</n:slot>. That also has the advantage of 
> not breaking any current code and allowing arbitrary default contents.

+1 for not breaking current code so my preferred solution would be what you suggest but with an added check so that:

if allowDefault="true" *and* there exists a n:slotdefault then take *only* the n:slotdefault content as default value,
else if only allowDefault="true" then use the whole contents of the slot as default value,
else bail out like it does now.

ciao
ste





More information about the Twisted-web mailing list