logo       

the "Cheetah files" (part 1): msg#00009

python.cheetah

Subject: the "Cheetah files" (part 1)

hi there,

i just want to share a nice "usage pattern" that i started
to use recently, nothing outstanding. one tipcal task is to
accomplish is:

''loop over a sequence and display data, if sequence is empty
show a notice.''

say you have to display a HTML bulleted list with a series
of message titles, until recently i've always written:

#if $seq
<ul>
#for $item in $seq
<li><a href="read?id=$item.id">$item.title</a></li>
#end for
</ul>
#else
<p class="info">No message found.</p>
#end if

ugly and messy. what about a:

<ul>
#for $item in $seq
<li><a href="read?id=$seq.id">$seq.title</a></li>
#end for
</ul>

#unless $seq
<p class="info">No message found.</p>
#end unless

you spare one level of indentation. yes, if the sequence is empty
you generate a <ul></ul> pair, but you can always write:

<ul>
#for $item in $seq
<li><a href="read?id=$seq.id">$seq.title</a></li>
#end for

#unless $seq
<li class="info">No message found.</li>
#end unless
</ul>


i'm interested in your tricks too.

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