[Zope-CMF] problems rendering ZPT in Python Script

Tres Seaver tseaver@zope.com
13 May 2002 11:32:22 -0400


On Mon, 2002-05-13 at 11:35, Gr=E9goire Weber wrote:

> oups, that was fast! :-)
>=20
> I found what I have to do to solve the problem (use 'context' instead of=20
> 'container' in getattr):
>=20
>   obj =3D getattr(context, '%s%s' % (context.template_name, '_anon'))
>   html =3D obj() # works!!!
>=20
> But I do not really understand why it does not work with 'container'.
>=20
> Especially after reading the following lines in=20
> http://www.zope.org/Documentation/ZopeBook/ScriptingZope.stx:
>=20
>    [...]
>    Context=20
>       The Context binding defaults to the name context. This variable=20
>       refers to the object that the script is called on.=20
>    Container=20
>       The Container binding defaults to the name container. This=20
>       variable refers to the folder that the script is defined in.=20
>    [...]
>=20
> I suppose that the reason is somehow related to the skin functionality
> of the CMF. Taking 'context' should not be a problem because it finds the
> correct ZPT going through the skin path as normal.
>=20
> If somebody has a explanation I'll write a small receipe in zopelab.

'container' is going to be the folder or directory view under
'portal_skins' where the template lives;  it *won't* be wrapped in the
current context, which explains the behavior you report.

In general, using 'container' with skin methods is almost *never* going
to produce useful results (even with "stock" ZPT, it won't do what you
expect unless 'context' and 'container' happen to be the same object).


> Greetings, Greg
>=20
> P.S.: Printing obj.aq_chain produces an error (obj.aq_chain() also).

'aq_chain' would only be available to "trusted" code, i.e., in the Zope
debugger.

>=20
> P.P.S.: 'container.topic_view_body_anon' doesn't work neither, so the=20
>         behaviour is at least the same.

Right.

Tres.
--=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com