Hi all, There must be a better way than: <span tal:omit-tag="" tal:condition="python: this_object is not None"> <span tal:replace="python: this_object.getSomethingBig() " /> </span> The following gives an attribute error if 'this_object' is None: <span tal:replace="python: test(this_object is not None, this_object.getSomethingBig(), '')" /> test() seems to always evaluate both params no matter what. In a word, is there a ZPT equivalent to the following python code without nesting <span></span> again and again? if this_object is not None and this_object.getSomethingBig(): result = self.getSomethingEvenBigger() I'm putting too many <span></span> nests to prevent this annoying attribute error in NeoBoard skins. Any help will be appreciated. Regards, Wankyu Choi --------------------------------------------------------------- To the dedicated staff at NeoQuest, language is not a problem to be dealt with, but an art waiting to be performed. --------------------------------------------------------------- Wankyou Choi CEO/President NeoQuest Communications, Inc. 3rd Floor, HMC Bldg., 730-14, Yoksam-dong, Kangnam-gu Seoul, Korea Tel: 82-2 - 501 - 7124 Fax: 82-2-501-7058 Corporate Home: http://www.neoqst.com Personal Home: http://www.neoboard.net e-mail: wankyu@neoqst.com ---------------------------------------------------------------
Hi Wankyu Choi,
Hi all,
There must be a better way than:
<span tal:omit-tag="" tal:condition="python: this_object is not None"> <span tal:replace="python: this_object.getSomethingBig() " /> </span>
"tal:condition" is evaluated before "tal:replace" (see Zope Book, Appendix C, ZPT Reference), thus You should be able to save at least one <span> by saying: <span tal:condition="python: this_object is not None" tal:replace="python: this_object.getSomethingBig() " />
The following gives an attribute error if 'this_object' is None:
<span tal:replace="python: test(this_object is not None, this_object.getSomethingBig(), '')" />
test() seems to always evaluate both params no matter what. [...]
Yes, "test" is a "normal" function, and no magic syntax; arguments are always evaluated before the function "test" is evaluated. Cheers, Clemens
On Tue, Nov 05, 2002 at 02:08:42PM +0100, Clemens Robbenhaar wrote:
The following gives an attribute error if 'this_object' is None:
<span tal:replace="python: test(this_object is not None, this_object.getSomethingBig(), '')" />
test() seems to always evaluate both params no matter what.
What's wrong with the usual python idiom? <span tal:replace="python: (foo is not None and foo.bar()) or ''"> </span> -- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
Clemens Robbenhaar writes:
... "tal:condition" is evaluated before "tal:replace" (see Zope Book, Appendix C, ZPT Reference), thus You should be able to save at least one <span> by saying:
<span tal:condition="python: this_object is not None" tal:replace="python: this_object.getSomethingBig() " /> You can also use
<span tal:replace="python: this_object and this_object.getSomethingBig()" /> Dieter
participants (4)
-
Clemens Robbenhaar -
Dieter Maurer -
Paul Winkler -
Wankyu Choi