[Zope-CMF] simple (I think :-) TAL/python expression question

Sam Brauer sam@webslingerz.com
Tue, 10 Jun 2003 16:34:14 -0400


gmane wrote:
> I have the following snippet of code:
> (the "nwType" and such relate to a javascript menu library I'm using)
> 
> --------------
> <div nwType="menuComponent" width="150">
>      <metal:block tal:repeat="item menu_items">
>           <div tal:condition="python:item.folder_type == 'division'"
> nwType="menuNode" tal:attributes="dispText item/Title; action
> string:window.location='${portal_url}/${item/getId}';">
>           </div>
>      </metal:block>
> </div>
> ----------------
> 
> my question is, how do I code the "python:item.folder_type ==  ????? " line
> so that instead of the hard-coded 'division' string, I'm comparing against a
> "tal:define=blah tab/id" statement earlier?   Actually, I'm assuming I need
> to make the defined variable global, but I can't come to grips with the
> syntax for the python expression.
> 
> and of course, I realize this whole ugly ball of code probably needs to be
> moved out of the template and into a script... but I'm saving that for my
> next trick :-)
> 
> thanks for any clues anyone can provide...
> 
> Larry
> 
> 

You either need to define "blah" globally as you said, or define it in a 
tag that surrounds the context where you want to refer to it:

<span tal:define="blah tab/id">
  ...
    <div tal:condition="python:item.folder_type == blah">
       ...
    </div>
  ...
</span>

In either case, your python expression would simply be:
item.folder_type == blah

> 
> 
> 
> _______________________________________________
> Zope-CMF maillist  -  Zope-CMF@zope.org
> http://mail.zope.org/mailman/listinfo/zope-cmf
> 
> See http://collector.zope.org/CMF for bug reports and feature requests


-- 
Sam Brauer
Systems Programmer
sam@webslingerZ.com