Re: [PHPTAL] Advanced TALES
Hi, I think in that case best solution would be to make TALES more powerful, but I wonder how much powerful? Should I add math expressions? String concatenation? Should I allow passing of function arguments? What the syntax should be like? Maybe you can find some inspiration from the Nevows tal like template language: http://divmod.org/trac/browser/trunk/Nevow/doc/howto/xmltemplates.xhtml The one thing I've been wishing for more than any other is a better way to handle date formatting. Maybe span tal:content=myobj/myfuncOutputtingDate/dateFormat!%d-%m%y / ? T foo/bar EQ baz/quz foo/bar + baz/quz Should modifiers work inside TALES? How do you mark end of modifier's content? foo/bar + php:foo() php:foo() + bar/baz http://phptal.org/wiki/doku.php/improvedtales ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal -- Tarjei Huse Mobil: 920 63 413 ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
On 25-11-2009 at 08:49:18 tarjei tar...@nu.no wrote: Hi, I think in that case best solution would be to make TALES more powerful, but I wonder how much powerful? Should I add math expressions? String concatenation? Should I allow passing of function arguments? What the syntax should be like? Maybe you can find some inspiration from the Nevows tal like template language: http://divmod.org/trac/browser/trunk/Nevow/doc/howto/xmltemplates.xhtml The one thing I've been wishing for more than any other is a better way to handle date formatting. Maybe span tal:content=myobj/myfuncOutputtingDate/dateFormat!%d-%m%y / ? This one actually can be handled with modifiers: tal:content=date:%d-%m%y myobj/myfuncOutputtingDate phptal_tales_date($expr) { list($format,$value) = explode(' ',$expr,2); return 'date('.$format.','.phptal_tales($value).')'; } -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
On 24-11-2009 at 23:43:16 Werner li...@mollentze.co.za wrote: Given this, one can speculate about a more leal-life example, which even a new TAL user would easily be able to pick up: option tal:attributes=selected compare:item/value,saved/value tal:content=item/value/option Just my 2 cents ;) But how is that better than item/value == saved/value? -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
Simply because it allows for multiple modifier parameters (of which some can be optional), which in turn can allow for more flexibility in certain kinds of modifiers, e.g: tal:block tal:content=fullName:name/title,name/first,/name/last/tal:block Kornel Lesiński wrote: On 24-11-2009 at 23:43:16 Werner li...@mollentze.co.za wrote: Given this, one can speculate about a more leal-life example, which even a new TAL user would easily be able to pick up: option tal:attributes=selected compare:item/value,saved/value tal:content=item/value/option Just my 2 cents ;) But how is that better than item/value == saved/value? ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
On 25-11-2009 at 11:35:43 Werner li...@mollentze.co.za wrote: Simply because it allows for multiple modifier parameters (of which some can be optional), which in turn can allow for more flexibility in certain kinds of modifiers, e.g: tal:block tal:content=fullName:name/title,name/first,/name/last/tal:block That is possible currently: function phptal_tales_fullname($expr) { foreach(explode(',',$expr) as $subexpr) … } But that's a separate modifier. What I'm talking about is modification of the default path: modifier (which is the default). I think that is intuitive to someone who knows TALES and PHP: tal:attributes=selected current/id == selected_id The goal is to free users from having to write many modifiers, especially for common and trivial cases, and to provide something generic and intuitive instead. If you want to repeat table headers every 5 rows, what would you do? tr tal:condition=repeat/row/index mod 5 == 0 Should PHPTAL come with dozens of built-in modifiers? tr tal:condition=on-every-nth:5,repeat/row/index -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
I'd like TALES to be made more powerful. The changes won't affect those who don't want to use the new capabilities, so I don't see any harm in extending TALES. ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
On 17-11-2009 at 18:37:30 Iván Montes drsl...@pollinimini.net wrote: option tal:attributes=selected ?php $ctx-item-index == $ctx-selected ?foo/option This would work nicely with syntax highlighting and other editor/IDE features, is common enough for PHP developers and allows for arbitrary complex expressions. That doesn't look any more elegant than selected php:item.index == selected, and isn't any simpler to novice users, because you have to know $ctx- hack. The Tales parser just detects that the start of the expression is the ?php (or even ?) and then fetches all the contents until ? is found (PHP's tokenizer could even be used to avoid false positives). The whole PHP chunk is then outputted in the generated file where the $ctx-path() call would go for normal tales expressions. This would probably mean that the source template will need to be preprocessed, since as far as I know, processing instructions are not allowed inside attribute values. PHPTAL already does that. By the way, if you decide to go for extending Tales, I think it'll be very dangerous to allow function calling from them. Even if you try to add some white-listing security feature, it could always be prone to abuse and a possible attack vector. It's already possible in TALES using php: syntax. -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
On 17-11-2009 at 18:42:50 Iván Montes drsl...@pollinimini.net wrote: After looking at the wiki page examples, couldn't we solve this with specialized tales modifiers? This is taken straight from one of my pages: a tal:condition=php:pager.getNumberOfPages() GT 1 AND pager.getCurrentPage() LT pager.getNumberOfPages()-1 href=${php:pager.getURL(pager.getNumberOfPages())}#p${latest_post/id}Last »/a I could replace it with one-off special modifier, or redundant method in pager class, but I'm not sure if that's the best thing to do, and definitely it's not on path of least resistance. Why not write it like this: a tal:condition=pager/getNumberOfPages GT 1 AND pager/getCurrentPage LT pager/getNumberOfPages-1 href=${pager/getURL(pager/getNumberOfPages)}#p${latest_post/id}Last »/a ? -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
a tal:condition=php:pager.getNumberOfPages() GT 1 AND pager.getCurrentPage() LT pager.getNumberOfPages()-1 href=${php:pager.getURL(pager.getNumberOfPages())}#p${latest_post/id}Last /a Why not write it like this: a tal:condition=pager/getNumberOfPages GT 1 AND pager/getCurrentPage LT pager/getNumberOfPages-1 href=${pager/getURL(pager/getNumberOfPages)}#p${latest_post/id}Last /a Or JavaBeans way :) a tal:condition=pager/numberOfPages GT 1 AND pager/currentPage LT pager/numberOfPages-1 href=${pager/getURL(pager/numberOfPages)}#p${latest_post/id}Last /a Where pager/numberOfPages is looking for getter first :) -- Regards, Łukasz Palka ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
While I was looking at the pager example, I couldn't help but think this could be fixed by having a few helper classes for this; helper classes that would make your phptal code cleaner and abstract out certain typical tasks of a pager. The same could be said for the dropdown scenario. All in all, I hate having explicit code in my templates, why can't things in phptal be fixed in the phptal way? ;-) Best, Tjerk 2009/11/18 Kornel Lesiński kor...@aardvarkmedia.co.uk: On 17-11-2009 at 18:42:50 Iván Montes drsl...@pollinimini.net wrote: After looking at the wiki page examples, couldn't we solve this with specialized tales modifiers? This is taken straight from one of my pages: a tal:condition=php:pager.getNumberOfPages() GT 1 AND pager.getCurrentPage() LT pager.getNumberOfPages()-1 href=${php:pager.getURL(pager.getNumberOfPages())}#p${latest_post/id}Last »/a I could replace it with one-off special modifier, or redundant method in pager class, but I'm not sure if that's the best thing to do, and definitely it's not on path of least resistance. Why not write it like this: a tal:condition=pager/getNumberOfPages GT 1 AND pager/getCurrentPage LT pager/getNumberOfPages-1 href=${pager/getURL(pager/getNumberOfPages)}#p${latest_post/id}Last »/a ? -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal -- -- Tjerk ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
[PHPTAL] Advanced TALES
There are few cases where simple TALES (expressions like foo/bar/baz) isn't working well, most often comparison of selected option, PHPTAL's pythonified/xmlized PHP syntax has gotchas and it's confusing to jump between the two. I think in that case best solution would be to make TALES more powerful, but I wonder how much powerful? Should I add math expressions? String concatenation? Should I allow passing of function arguments? What the syntax should be like? foo/bar EQ baz/quz foo/bar + baz/quz Should modifiers work inside TALES? How do you mark end of modifier's content? foo/bar + php:foo() php:foo() + bar/baz http://phptal.org/wiki/doku.php/improvedtales -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
On 17-11-2009 at 12:35:02 Marco Pivetta ocram...@gmail.com wrote: I know it's not an elegant solution, but it's a solution and I already use it: what about tal:define? It is already possible to fix those tales problems wrapping content within a tal:omit-tag-ed definer element or directly a tal:define block. I don't understand how does it help. If you have selected_id variable and want to select option with that ID, how would you do it with tal:define? without help of php: modifier? even/odd classes can be done with pure TALES and tal:omit-tag, but it's ugly: tr class=even tal:omit-tag=repeat/row/odd tr class=odd tal:omit-tag=repeat/row/even /tr /tr I'm probably loosing the point of the discussion, but I don't really see any reason to make the syntax more complex and also a bit heavyer to compute for the parser... This would be heavier only once during template compilation, so performance is not a problem. -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
After looking at the wiki page examples, couldn't we solve this with specialized tales modifiers? option tal:repeat=opt options tal:attributes=selected equals: opt, selected_option/ tr tal:repeat=row rows tal:attributes=class ternary:repeat.row.odd, 'odd', 'even'/ It's a bit more verbose but they are quite declarative and should be easy to implement in the current PHPTAL infrastructure. /imv On 11/17/09 2:05 PM, Kornel Lesiński wrote: On 17-11-2009 at 12:35:02 Marco Pivetta ocram...@gmail.com wrote: I know it's not an elegant solution, but it's a solution and I already use it: what about tal:define? It is already possible to fix those tales problems wrapping content within a tal:omit-tag-ed definer element or directly a tal:define block. I don't understand how does it help. If you have selected_id variable and want to select option with that ID, how would you do it with tal:define? without help of php: modifier? even/odd classes can be done with pure TALES and tal:omit-tag, but it's ugly: tr class=even tal:omit-tag=repeat/row/odd tr class=odd tal:omit-tag=repeat/row/even /tr /tr I'm probably loosing the point of the discussion, but I don't really see any reason to make the syntax more complex and also a bit heavyer to compute for the parser... This would be heavier only once during template compilation, so performance is not a problem. ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] Advanced TALES
To maintain proper bc I would suggest another namespace, like ntales (new tales) The problem of modifier scope is difficult, unless you can introduce syntax like this: (php:foo()) + foo/bar Braces around the modifier code would define the scope, but this is still error prone if you decide to have something like php:foo('(hi') in which the brace count would screw up unless you do tokenizing. To be honest, to solve the option problem I just add a selected attribute in my option list and add selected exists: row/selected which works fine, no need to pass two variables into phptal. On 11/17/09, Kornel Lesiński kor...@aardvarkmedia.co.uk wrote: There are few cases where simple TALES (expressions like foo/bar/baz) isn't working well, most often comparison of selected option, PHPTAL's pythonified/xmlized PHP syntax has gotchas and it's confusing to jump between the two. I think in that case best solution would be to make TALES more powerful, but I wonder how much powerful? Should I add math expressions? String concatenation? Should I allow passing of function arguments? What the syntax should be like? foo/bar EQ baz/quz foo/bar + baz/quz Should modifiers work inside TALES? How do you mark end of modifier's content? foo/bar + php:foo() php:foo() + bar/baz http://phptal.org/wiki/doku.php/improvedtales -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal -- -- Tjerk ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal