Search code examples
pyramidtemplate-enginechameleontemplate-tal

Pyramid Chameleon Tal:condition 'Not' issue


I am trying to display conditional text in a Pyramid Chameleon template. Basically, checking if the dictionary key 'maxed_out_alerts' is empty (false) or has a string 'yes' in it.

<p tal:condition="not:maxed_out_alerts"><h3>Maxed Out.</h3></p>
<p tal:condition="maxed_out_alerts"><h3>Not Maxed Out</h3></p>

When 'maxed_out_alerts' is an empty string, 'Maxed Out' is only displayed (correctly). However, If 'maxed_out_alerts' contains 'yes' string both 'Maxed Out' and "Not Maxed Out' are displayed (incorrectly).

It seems that the NOT is always evaluated to a true condition. It should display one or the other messages not both. What am I doing wrong? thanks


Solution

  • For TAL conditionals in python you can say python: and then use a python syntax conditional

    <p tal:condition="python:len(maxed_out_alerts) > 0"><h3>Maxed Out.</h3></p>