Hi, How do one ascieve the equivilent to: <dtml-in getRecords> ... <dtml-else> Nothing in getRecords </dtml-if> Using conditions produce over complicated markup, which I would like to avoid. <div tal:define="records python:here.getRecords()"> <div tal:condition="records" tal:repeat="record records"> ... </div> <div tal:condition="not:records"> Nothing in getRecords </div> </div> I guess the answer is no, but I hope there is a smarter way to do this. Best Regards, Johan Carlsson -- Easy Publisher Developers Team Johan Carlsson johanc@easypublisher.com Mail: Birkagatan 9 SE-113 36 Stockholm Sweden Phone +46-(0)8-31 24 94 Fax +46-(0)8-673 04 44 Mobil +46-(0)70-558 25 24 http://www.easypublisher.com
Johan Carlsson [EasyPublisher] wrote:
Hi, How do one ascieve the equivilent to:
<dtml-in getRecords> ... <dtml-else> Nothing in getRecords </dtml-if>
Using conditions produce over complicated markup, which I would like to avoid.
<div tal:define="records python:here.getRecords()"> <div tal:condition="records" tal:repeat="record records"> ... </div> <div tal:condition="not:records"> Nothing in getRecords </div> </div>
I guess the answer is no, but I hope there is a smarter way to do this.
AFAIK this is not possible yet, but it will probably come, i have no idea when. I wondered about this some weeks ago, also, here are my notes about it: http://openspirit.homelinux.net/noowiki/zope/Condition Greetings, Florian -- Florian Konnertz --- http://www.florian-konnertz.de http://openspirit.homelinux.net/noowiki/FrontPage Improved ZWiki about all topics, especially consciousness research and wisdom traditions
Florian Konnertz wrote:
I wondered about this some weeks ago, also, here are my notes about it: http://openspirit.homelinux.net/noowiki/zope/Condition
(Moving to ZPT list) Thanks! Re-reading Guido's post gave me an idea: <ul tal:condition-group="flavor" tal:repeat="variety icecreams"> <li tal:condition="flavor python:variety in ('Cherry', 'Strawberry')"> I like <span tal:replace="variety">this flavor</span> very much. </li> <li tal:condition="flavor python:variety in ('Vanilla', 'Chocolate')"> I like <span tal:replace="variety">this flavor</span>. </li> <li tal:condition="flavor python:variety in ('Coffee', 'Mint Chip')"> I don't like <span tal:replace="variety">this flavor</span>. </li> <li tal:condition="flavor default"> I haven't tried <span tal:replace="variety">this flavor</span>. </li> </ul> So, tal:condition-group sets up a variable and a scope. Within that scope, all tal:condition statements that precede the conditional expression with the group name and whitespace are grouped -- once one of them has evaluated true, all of the following ones will short-circuit evaluate to false. The variable will be false until one of the grouped conditions is true, and true thereafter. It can be used to negate the group condition or combine it with other conditions. There are two ways to say "else". One is to use a true-valued literal, as in 'fred default'. The other is 'not:fred'. The difference is that 'fred default' *also* sets 'fred' true, while 'not:fred' does not. You can also spell "notelse", that is, test whether any prior condition succeeded, using plain 'fred'. The question arises of how this would interact with a nested tal:repeat. I suggest that if one wants to "reset" the group within the tal:repeat, one must re-declare the group there. Example: <tal:x condition-group="fred"> <tal:x condition="fred default">Always</tal:x> <tal:loop repeat="n python:range(3)" condition-group="fred"> <tal:x condition="fred repeat/n/first">First</tal:x> <tal:x condition="not:fred">Not First</tal:x> <tal:x condition="fred repeat/n/last">Last</tal:x> </tal:loop> <tal:x condition="fred default">Never</tal:x> <tal:x condition="fred">Always</tal:x> </tal:x> ...would produce: Always First Not First Not First Last Always Note the subtle difference between using 'not:fred' and 'fred default' for "Not First". If I had used the latter, 'fred' would become true, and 'fred repeat/n/last' would never succeed. Cheers, Evan @ 4-am
participants (3)
-
Evan Simpson -
Florian Konnertz -
Johan Carlsson [EasyPublisher]