[Zope] Re: returning a macro from a pythonscript
Gaute Amundsen
gaute at div.org
Mon Mar 5 03:00:44 EST 2007
On Friday 02 March 2007 17:06, Tres Seaver wrote:
> Gaute Amundsen wrote:
> > On Friday 02 March 2007 11:20, Andreas Jung wrote:
> >> --On 2. März 2007 11:10:57 +0100 Gaute Amundsen <gaute at div.org> wrote:
> >>> I have tried many varieties, but I can't remember ever getting it to
> >>> work...
> >>>
<snip>
> > foo = restrictedTraverse('/foo/bar/index.html/macros/mymacro')
> > return foo()
> >
> > But of course foo is a list, and I can't see a way I can use any of the
> > contents..
>
> You can't "use it", only inline it into a calling template. E.g.:
>
> ##Script (Python) "random_macro"
> from random import choice # may need module security assertion
> macros = context.some_template.macros
> macro1 = macros['one']
> macro2 = macros['two']
> macro3 = macros['three']
> return choice((macro1, macro2, macro3))
>
> The template would just do:
>
> <div metal:use-macro="context/random_macro" />
>
>
>
> Tres.
I see..
So it is the use-macro statement that takes the datastructure, and turns it
into a tempate/html.
I my case I think I will rather try to use a wrapper approach.
In script: return container.ajax_tpl(mcr=my_macro_from_big_tpl)
In ajax_tpl: <div metal:use-macro="options/mcr" />
But it's good to know the other option allso.
Thanks.
On Friday 02 March 2007 22:36, David H wrote:
>
> With Zope 2 I use python scripts to fill my "content" area (2-3 column
> css) with macros like so:
> # python script:
> return container.Budget.BudgetMaint.macros['budgetMaint']
>
> It works
>
> All best,
>
> David H
In other words, a script can return a macro, but is has to be into a
use-macro tag.
OK
Thanks.
More information about the Zope
mailing list