On Wed, Mar 10, 2004 at 09:54:07PM +0100, Dieter Maurer wrote:
Florian Schulze wrote at 2004-3-9 11:44 +0100:
I would like to know wether there is a way to test if a macro evaluates to nothing.
I tried the following: <div tal:condition="here/my_macros/macros/macro_name" metal:use-macro="here/my_macros/macros/macro_name"> </div>
But the macro returns a tree of lists and tuples.
Sure, this is the macro code. It is unlikely to be empty...
When you want to check, whether the result of macro rendering is empty, then you must render the macro and look at the result. In the trivial case (the macro is independent of arguments defined in the caller), you can wrap your macro use in a PageTemplate, call this template and check its result. When your macro needs arguments, you must pass them to the template.
But the macro is unlikely to produce literally nothing... usually there will be at least a bunch of whitespace and/or some empty tags. At the least you will have to write the macro so that all its tags are replaced with a blank value when appropriate, call the macro in a wrapper template as Dieter suggests, and then in the final template that calls the wrapper, strip() the result. I have to wonder if there's a cleaner design that will get the end result you want. Remember that macros are evaluated before TAL. I think you could set a global variable in the macro and check it in the calling template... but I haven't tried. Or maybe the variables needed by the macro could be retrieved by the template that uses the macro, e.g. from a python script. -- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's THE SPOOGE! (random hero from isometric.spaceninja.com)