2009/5/6 Juan Pablo Scaletti <[email protected]>: > > That can be especially annoying because: > > 1. Unlike regular python, a blank line break the block of code. > > $if something: > ....<p>In the if-block</p> > ....<p>Still in</p> > > ....<p>Not in the if-block anymore!</p>
Even I was troubled with this. Filed a bug. https://bugs.launchpad.net/webpy/+bug/372540 > 2. The $if, $for, etc. *must* be the first thing in a line (besides > spaces). > I would like to do something like this: > > <li $if id == 'a': class="selected" $endif >...</li> > <li $if id == 'b': class="selected" $endif >...</li> > > but instead I have to do the much uglier: > > <li \ > $if id=='a': class="selected"\ >>...</li> > <li \ > $if id=='b': class="selected"\ >>...</li> Try this: $def ifelse(predicate, consequence, alternative=""): $if predicate: $:consequence\ $else: $:alternative\ $ id = 'a' <li $:ifelse(id == 'a', 'class="selected"')>...</li> Even better add a utility function. def ifelse(predicate, consequence, alternative=""): if predicate: return consequence else: return alternative How about adding this to web.template builtins by default? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/webpy?hl=en -~----------~----~----~----~------~----~------~--~---
