Please explain, I've got this page template, with an empty title. <h2 tal:condition="template/title">Has a Title</h2> <h2 tal:condition="template/id">Has an Id</h2> <h2 tal:condition="template/title | template/id">Has a Title or Id</h2> The rendered out put is: <h2>Has an Id</h2> So... <h2 tal:condition="template/title">Has a Title</h2> The tag is omitted because there is no title, which is what I would expect (empty string evaluates to false). <h2 tal:condition="template/id">Has an Id</h2> The tag is included because there is an Id, again what I would expect. <h2 tal:condition="template/title | template/id">Has a Title or Id</h2> The tag is omitted (what???) but there is an id, I would expect this to evaluate to true (false | true == true). (In fact.. anything to the right of the pipe is not even accessed/called) Is there something wrong in my thinking? -Brian
At the risk of being thought somewhat lateral here...
<h2 tal:condition="template/title | template/id">Has a Title or Id</h2>
I'd do this as: <h2 tal:condition="python:template.title or template.id">Has a Title or Id</h2> ...since the rules for Python expressions are generally easier to understand or clarify with the use of parentheses. :) ben
After some more searching I found my answer. The pipe is not an OR operator in TALs. Instead it separates path expressions and the first expression that exists is evaluated. -Brian Ben Last (Zope) wrote:
At the risk of being thought somewhat lateral here...
<h2 tal:condition="template/title | template/id">Has a Title or Id</h2>
I'd do this as: <h2 tal:condition="python:template.title or template.id">Has a Title or Id</h2> ...since the rules for Python expressions are generally easier to understand or clarify with the use of parentheses. :)
ben
_______________________________________________ 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 )
Brian Brinegar wrote:
<h2 tal:condition="template/title">Has a Title</h2> <h2 tal:condition="template/id">Has an Id</h2> <h2 tal:condition="template/title | template/id">Has a Title or Id</h2>
I believe what you really may be looking for is: <h2 tal:content="template/title_or_id"/> cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (3)
-
Ben Last (Zope) -
Brian Brinegar -
Chris Withers