[PHPTAL] Re: PHP Tales custom modifiers syntax (James McLean)

Kornel Lesinski kornel at aardvarkmedia.co.uk
Wed Jan 2 11:32:33 CET 2008


On Wed, 26 Dec 2007 14:57:31 -0000, Patrick Burke <hewdaily at gmail.com>  
wrote:

> <tal:block tal:define="global prodSellPrice
> php:prodRow.getProductPrintableSellPrice()"/>
> <td tal:content="money: prodSellPrice"></td>
[...]
> I haven't tried doing the define in the <td/> tag - I just like to keep  
> that stuff separated.

It should work like this:

<td tal:define="prodSellPrice
  php:prodRow.getProductPrintableSellPrice()"
  tal:content="money: prodSellPrice">

The benefit is that you avoid creation of global variables, so it will  
work reliably in recursive macros, etc.


However, it's not even neccessary. In 1.1.9 there's  
phptal_tale($expression,$nothrow)* function which you can use to evaluate  
rest of the expression, e.g.:

function phptal_tales_rot13($expr, $nothrow)
{
	return 'rot13('.phptal_tale($expr,$nothrow).')';
}


Currently that's the best way to handle nested tales modifiers.

-- 
regards, Kornel

*) phptal_tales(), which is availble in older versions and isn't an ugly  
hack, will work as well, but only for expressions that don't use the "|"  
operator.



More information about the PHPTAL mailing list