Re: [PHPTAL] Using tal:repeat as condition
On 04-09-2008 at 10:12:37 Christoph Frick [EMAIL PROTECTED] wrote: But it causes error Unable to find path number in current scope. Is this possible to make such a condition? I know I could generate in PHP something like item/isThird but I wish to keep my PHP code clean from such hacks. you try to divide the numbers (/ is interpreted by php). use dots instead. number, key, ... might even be functions thus adding () at the might be needed (i am not sure, if this still the case with phptal). For repeat object you must use only ., without (). -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
[PHPTAL] Conditional class-attribute
Hi, I am trying to switch from Smarty to phptal. I am enjoying it a lot in the current project and plan to use it on further developments. One task always hits me where I end up having to mix the presentation back to my PHP code. But maybe there is a phptal-based solution. In loops, I want to set different class attributes at the same time, depending on certain criterias, e.g. ul liRegular/li li class=currentCurrently selected item/li li class=lastLast item/li /ul I can have either last set, using: ul tal:repeat=item items li tal:content=item.content tal:attribute=class php:repeat.item.end ? 'last' : '' Regular/li /ul Or have my current flag set, using: ul tal:repeat=item items li tal:content=item.content tal:attribute=class php:item.isCurrent ? 'current' : '' Regular/li /ul 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: ul tal:repeat=item items li tal:content=item.content tal:attribute=class php:item.isCurrent ? ( repeat.item.end ? 'last current' : 'current' ) : (repeat.item.end ? 'last' : '') Regular/li /ul Any other suggestion on how to acchieve this? Cheers, Ernesto ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Conditional class-attribute
On 08-09-2008 at 12:27:50 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') http://phptal.motion-twin.com/manual/en/split/ar05s07.html#tales-php or you can use the ${} syntax: li class=${php:...} ${php:...} alternatively, if you work with such classes a lot, you can make syntax nicer by writing your own expression modifier: tal:attributes=class my_classes:repeat.item and create: function ($argument,$nothrow) { return 'php_function_to_execute_when_template_runs('.phptal_tales($argument,$nothrow).')'; } http://phptal.motion-twin.com/manual/en/split/ar06s08.html -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Conditional class-attribute
Hi Kornel, Kornel Lesiński wrote: on 08.09.2008 15:29: On 08-09-2008 at 12:27:50 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/getNameSession/a/li /tal:block /div http://phptal.motion-twin.com/manual/en/split/ar05s07.html#tales-php or you can use the ${} syntax: li class=${php:...} ${php:...} That is true, and even looks a lot Smarty-ish. :) alternatively, if you work with such classes a lot, you can make syntax nicer by writing your own expression modifier: tal:attributes=class my_classes:repeat.item and create: function ($argument,$nothrow) { return 'php_function_to_execute_when_template_runs('.phptal_tales($argument,$nothrow).')'; } http://phptal.motion-twin.com/manual/en/split/ar06s08.html Indeed also a good suggestion, will keep that concept in mind when developing further. Thanks a lot for your time and hints! I will keep up following this list. Cheers, Ernesto ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Conditional class-attribute
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/getNameSession/a/li /tal:block /div 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). -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Conditional class-attribute
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/getNameSession/a/li /tal:block /div 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). Cheers, Ernesto ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal