On 05-03-2009 at 10:15:52 Mr Brightside <scors...@epf.pl> wrote:

I'm trying to apply some css classes to alternate rows in my table.
According to the PHPTAL manual, you can use this:

tal:attributes="class php: repeat.ranking.odd ? 'odd' : NULL"

It works fine, but there's a better way suggested using a custom modifier:

tal:attributes="class css-odd:repeat/ranking/odd"

Now, I have no idea how to go about writing this custom modifier.
First, I don't think the name `css-odd` will work since you can't name a php function like so:

function phptal_tales_css-odd($src, $nothrow) {}

You can name it phptal_tales_css_odd(…)

But this is not the problem (you can change the modifier name...).
In fact, I'm not quite sure what the body of this function should be like.

phptal_tale($src, $nothrow) will return a string that contains PHP expression 
that evaluates whatever was passed to the modifer.

return '(' . phptal_tale($src, $nothrow) . ' ? "even" : "odd" )';

You can create your own custom syntax for your modifier by parsing $src, e.g.:
list($expression,$even_class,$odd_class) = explode(' ',$src);

regards, Kornel

PHPTAL mailing list

Reply via email to