[Zope] Wrapping pre-existing content
J M Cerqueira Esteves
jmce@artenumerica.com
Thu, 8 Mar 2001 13:37:18 +0000
On Thu, Mar 08, 2001 at 10:52:18AM -0000, Phil Harris wrote:
> I've got a naive Python Script (restricted) that looks like this:
>
> #===================
> import string
>
> a=context.restrictedTraverse(string.join(traverse_subpath,'/'),0)
> if a.meta_type == 'Folder':
> a=a.default_html
>
> h=context.aspire_html_header_orig(None,context)
> f=context.aspire_html_footer_orig(None,context)
> c=a(None,context)
>
> return h+c+f
> #===================
>
> However this has problems when rendering the header and footer (h & f), it's
> somehow losing the namespace and things such as PARENTS are no longer
> available.
Ooops, just now I noticed you were already using a wrapper script as I was
suggesting...
I was now going to suggest activating the namespace binding in the
python script, and instead of `context' passing `_' as the second argument
to the header and footer methods, but noticed that according to
bindings documentation:
"When the script is called from DTML, this is the caller's DTML namespace,
otherwise it is an empty namespace."
I can not test this now, but try to pass `context' as the first argument
of the DTML methods, not as the second one.
According to the documentation for the __call__ method of DTML Methods,
these look up names as items in the second argument, which should be a mapping
(it's common to use `_' there), but as *attributes* in the first argument.
Depending on what your header and footer need in terms of namespaces, it
could be necessary to pass the to-be-wrapped object to them, instead of
the `context' object.