logo       

Re: the "Cheetah files" (part 1): msg#00015

python.cheetah

Subject: Re: the "Cheetah files" (part 1)

Mike Orr wrote:

(...)
It sounds like to do exactly what you'd want would require a new
directive. But I can't think of any way that's cleaner than the
#if <UL> #for <LI> #end for </UL> #else Sorry, Charlie! #end if

model you posted. The ifNotMessage could be multiline too, so
it doesn't fit easily into a directive attribute.
infact the #for / #unless trick works just fine for my purposes
that's why i posted it to the ML.

#for could grow a section for "if list is empty", but we can't call
it #else because Python uses that clause for another purpose.
yeah, where sequence is "naturally exhausted" else: block is called.

And we don't want Python-lookalike directives behaving differently than
in Python.
it would be definitely a bad thing.

And actually implementing an "if empty" portion in #for
would be a lot of work. Since the "list" can be any iterable, you'd
have to prefetch the first element specially and do something different
if it didn't exist. And even if we did this, there's no place for
<UL> and </UL> -- not unless we added two more #for portions for
"before" and "after". It starts getting really complicated, and a
standard #for combined with #if/else or #unless starts looking the
epitome of readability by comparision.

this is something it could be implemented in version 2.0 of the
template system. maving from python-like statemenet to a more rule-based machinery, like zope's TAL or mozilla's XUL:

http://www.xulplanet.com/tutorials/xultu/templates.html

but this really would distort cheetah philosophy a lot. having rules
like #ifempty would look a bit strange. :)

later,
deelan




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise