Basic Template question : 'truthiness'
I thought I knew how this stuff worked, but this has gotten me banging my head against a wall. I'm trying to evaluate a condition expression, and I'm not getting what I expect when using path, and I get a different result when using python. The following expressions results=<span tal:content="results" /><br /> dosearch=<span tal:content="request/dosearch | string:NO SEARCH" /><br /> querytpe=<span tal:content="request/querytype | string:NO QUERYTYPE" /><br /> <!-- test with python: this gives me what I expect --> <div tal:condition="python:len(results) or request.get('dosearch',None) or request.get('querytype',None)">TRUE IN PYTHON</div> <-- This doesn't evaluate to true --> <div tal:condition="results | request/dosearch | request/querytype | nothing">THIS DOESN'T SHOW UP</div> ---- Produces: results=[] dosearch=NO SEARCH querytpe=mps TRUE IN PYTHON As you can see, the second expression doesn't evaluate to True. Can someone explain the subtleties I seem to be missing? Thanks, Mark
--On 11. Juni 2006 13:35:40 -0600 Mark Gibson <mark@dimensional.com> wrote:
<-- This doesn't evaluate to true --> <div tal:condition="results | request/dosearch | request/querytype | nothing">THIS DOESN'T SHOW UP</div>
As you can see, the second expression doesn't evaluate to True. Can someone explain the subtleties I seem to be missing?
The '|' inside a path expression is *not* a logical OR. Subsequent path expression will only be evaluated in case an earlier expression raised a KeyError or AttributeError(possibly only KeyError...you have to check the docs). Since 'results' evaluates perfectly without exceptionno other path expression is evaluted. This is documented more or less perfecly in the Zope Book (ZPT reference I think). -aj
Mark Gibson wrote:
I thought I knew how this stuff worked, but this has gotten me banging my head against a wall.
I'm trying to evaluate a condition expression, and I'm not getting what I expect when using path, and I get a different result when using python. The following expressions
results=<span tal:content="results" /><br /> dosearch=<span tal:content="request/dosearch | string:NO SEARCH" /><br /> querytpe=<span tal:content="request/querytype | string:NO QUERYTYPE" /><br />
<!-- test with python: this gives me what I expect --> <div tal:condition="python:len(results) or request.get('dosearch',None) or request.get('querytype',None)">TRUE IN PYTHON</div>
<-- This doesn't evaluate to true --> <div tal:condition="results | request/dosearch | request/querytype | nothing">THIS DOESN'T SHOW UP</div>
---- Produces: results=[] dosearch=NO SEARCH querytpe=mps TRUE IN PYTHON
As you can see, the second expression doesn't evaluate to True. Can someone explain the subtleties I seem to be missing?
Thanks, Mark _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
__________ NOD32 1.1592 (20060611) Information __________
This message was checked by NOD32 antivirus system. http://www.eset.com
Mark, Just looking at your second example: <-- This doesn't evaluate to true --> <div tal:condition="results | request/dosearch | request/querytype | nothing">THIS DOESN'T SHOW UP</div> If you replace '| nothing' with '| default' you will get "THIS DOESNT SHOW UP" David
David H wrote:
Mark Gibson wrote:
I thought I knew how this stuff worked, but this has gotten me banging my head against a wall.
I'm trying to evaluate a condition expression, and I'm not getting what I expect when using path, and I get a different result when using python. The following expressions
results=<span tal:content="results" /><br /> dosearch=<span tal:content="request/dosearch | string:NO SEARCH" /><br /> querytpe=<span tal:content="request/querytype | string:NO QUERYTYPE" /><br />
<!-- test with python: this gives me what I expect --> <div tal:condition="python:len(results) or request.get('dosearch',None) or request.get('querytype',None)">TRUE IN PYTHON</div>
<-- This doesn't evaluate to true --> <div tal:condition="results | request/dosearch | request/querytype | nothing">THIS DOESN'T SHOW UP</div>
---- Produces: results=[] dosearch=NO SEARCH querytpe=mps TRUE IN PYTHON
As you can see, the second expression doesn't evaluate to True. Can someone explain the subtleties I seem to be missing?
Thanks, Mark _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
__________ NOD32 1.1592 (20060611) Information __________
This message was checked by NOD32 antivirus system. http://www.eset.com
Mark, Just looking at your second example: <-- This doesn't evaluate to true --> <div tal:condition="results | request/dosearch | request/querytype | nothing">THIS DOESN'T SHOW UP</div>
If you replace '| nothing' with '| default' you will get "THIS DOESNT SHOW UP"
David
Mark, Sorry I misread your problem. My last post! *Sorry* :-) David
participants (3)
-
Andreas Jung -
David H -
Mark Gibson