Kornel Lesiński wrote: on 08.09.2008 16:02:
On 08-09-2008 at 14:53:10 Ernesto Baschny [cron IT] <[EMAIL PROTECTED]> wrote:

I could try some nested "?" expressions, but this turns out to be quite ugly, e.g. if I would have more than 2 classes to set

You can concatenate strings in php: expressions - just add spaces around ".", i.e.:

tal:attributes="class php:(a?'b':'c') . (d?' e':' f')"

Cool tip! I had already tried the "." concatenation but got no results, because of the missing spaces around the ".". Not I got it working, current looks like:

        <div tal:repeat="session sessions" tal:omit-tag="true">
<tal:block tal:define="currentClass php:session.isCurrent() ? 'act' : ''; lastClass php:repeat.session.end ? 'last' : ''"> <li tal:attributes="id string:tab-session-${session/getId}; class php:trim(currentClass . lastClass)"><a href="#" tal:content="session/getName">Session</a></li>

The trim() is not neccessary - spaces around "." are just part of syntax and are not added to the string.

Currently this code might create "actlast" classs. If that's not what you wanted, then change 'last' to ' last' and optionally keep trim() (HTML ignores superfluous spaces in class attribute, so it's just aesthetical matter).
Yes, that trim() is just for aesthetical reasons. Good catch and your solution is what I had here (but on 'act ', with a space-suffix).


PHPTAL mailing list

Reply via email to