Am 17.02.2014 08:11, schrieb Gerhard Schmidt:
> Hi
>
> I'm having a problem with pyramid and chameleon concerning macros.
>
> I have a PageTemplate with two macros. I'm trying to get a rendered
> version of one of the macros in a method.
>
> def test1() :
> renderer = get_renderer('templates/test.pt').implementation()
> renderer.macro = 'status'
> status = true
>
> return renderer.render(status=status)
>
> def test2() :
> renderer = get_renderer('templates/test.pt').implementation()
> renderer.macro = 'history'
> used = datetime.datetime.now()
>
> return renderer.render(used=used)
>
> When I only call test1() i get the Macro status rendered.
> When I only call test2() I get the Macro history rendered.
>
> When I call test1() and then test(2) i get an NameError: status in
> method test2, because the macro status is rendered not history. If i
> Call test2() an then test1() i get the NameError: used in test1()
>
> I Think I'm doing it wrong, but i couldn't find anywhere how i can
> render only a macro directly from code.
>
> Is there any documentation how to do this correctly.I have done some debugging and learned that the pagetemplate is cached when it's rendered. Once called for one macro it can't be used for another. The solution is to uncook the pagetemplate before rendering the second macro by setting renderer._cooked to False before calling render. Again it's not a clean solution. But i still haven't found a clean one. Maybe i would be clean to ad a method setMacro to the PageTemplate Class that sets the macro attribute and set the _cooked attribute to false if the macro is different to what was set before. Regards Estartu -- --------------------------------------------------------------------------- Gerhard Schmidt | http://www.augusta.de/~estartu | Fischbachweg 3 | | PGP Public Key 86856 Hiltenfingen | JabberID: [email protected] | on request Germany | |
signature.asc
Description: OpenPGP digital signature
