[Zope] TAL: test() or condition Howto?
Ivo van der Wijk
ivo@amaze.nl
Fri, 31 Jan 2003 15:33:56 +0100
On Fri, Jan 31, 2003 at 12:12:55PM +0100, Elena Schulz wrote:
> Hi,
>
> I have the followong TAL-expression:
>
> <td
> tal:content="structure python:here.test(myImportantCondition and
> myExpensiveMethod(), myExpensiveMethod(),
> 'myDefaultString')">myDefaultString</td>
>
> To execute 'myExpensiveMethod()' 'myImportantCondition' must be 'true'. But
> I want to avoid to execute 'myExpensiveMethod()' two times. How can I achive
> that? As default-value myDefaultString should be served.
>
I've given this some thought, and it's actually rather difficult (if you
want to invoke myExpensiveMethod() just once and only if myImportantCondition
is true).
Also most people don't seem to realize that test() doesn't do lazy evaluation -
the ZPT above will *always* invoke at least once, no matter what
myImportantCondition is.
My advice would be to use a pythonscript.
Cheers
Ivo
--
Drs. I.R. van der Wijk -=-
Brouwersgracht 132 Amaze Internet Services V.O.F.
1013 HA Amsterdam, NL -=-
T +31-20-4688336 F +31-20-4688337 Linux/Web/Zope/SQL/MMBase
W http://www.amaze.nl E info@amaze.nl Network Solutions
W http://vanderwijk.info E ivo@amaze.nl Consultancy
PGP http://vanderwijk.info/pgp -=-