[Zope] Tal:condition problem

KevinL darius@obsidian.com.au
20 Aug 2002 22:11:30 +1000


On Tue, 2002-08-20 at 22:03, KevinL wrote:
> How about:
> 
> <div tal:define="macroName request/form/id">
>   <metal:block use-macro="container/zptmac_memtask/macros/?macroName">
>     List
>   </metal:block>
> </div>
> 
> Combined with renaming your "id" field in your forms (or your macro
> names, either will do) so they match?  That munges the whole list of
> tal:conditions down to something more manageable...

Heh.  After posting this, I looked closer at your list below, and
realised you're altering both the macro file name, and the name of the
macro inside the file.

That'd require that you be able to replace multiple elements of the
macro name, rather than a single.  That's not doable atm.  I still
reckon it should be...  Then you'd be covered by a tal:define="macroName
string:container/zptmac_${request/id}task/macros/zptmac_${request/id}list".

Alternately, you can make all macros in macro files be called the same
thing - so you end up with a file "zptmac_mempending", which has a macro
called "std", and a "zptmac_memtask" which also has a macro called
"std", and you just alter one element of the path to the macro, based on
the id from the form.

KevinL

> > On Tuesday, August 20, 2002, at 07:18 , zope wrote:
> > 
> > > Hi All
> > > I am trying to execute a macro only if a condition is satisified.
> > > The code I am using is:
> > >  
> > > <div tal:condition="python:request.form['id'] == 't' | nothing"  
> > > metal:use-macro="container/zptmac_memtask/macros/zptmac_taskslist">
> > >       List
> > > </div>
> > > <div tal:condition="python:request.form['id'] == 'p' | nothing"  
> > > metal:use-macro="container/zptmac_mempending/macros/zptmac_pendlist">
> > >       List
> > > </div>
> > > <div tal:condition="python:request.form['id'] == 'w' | nothing"  
> > > metal:use-macro="container/zptmac_memweek/macros/zptmac_weeklist">
> > >       List
> > > </div>
> > >  <div tal:condition="python:request.form['id'] == 'a' | nothing"  
> > > metal:use-macro="container/zptmac_memall/macros/zptmac_alllist">
> > >       List
> > > </div>