[Zope-dev] Question to acquisition

Jim Fulton jim@digicool.com
Tue, 08 Jun 1999 11:53:04 +0000


Thomas Riedl wrote:
> 
> Hi again;
> 
> after some source code studies I found out that I can return filled-out
> DTML from my python code by calling the returned Doc.Temp.:
> 
>         ...
>         template=DocumentTemplate.HTMLFile("""<!--#var myvarname-->
>                                               <!--#var some_name-->""",
>                                         globals())
> 
>         ... do something, determine value for myvarname
> 
>         return template(globals(),

Eek.  Do you really want to pass globals()?

>                         myvarname=determined_result,
>                         some_name='hello')

Also, the mapping object should be the second parameter.

> 
> But as soon as I want to use inherited 

(You mean acquired ;)

> attributes (like e.g.
> standard_html_header), I get a keyword error from out of DT_String.py.
> 
> I saw that I can specify as well a mapping as a client when calling
> the template, but I do not know what to specify for each to get what
> I want:
> 
> / standard_html_header          <----- This Me Wants !!
>   Products /
>         MyProd /
>                 MyInstance /
>                         some_python_code   <--- Therein I want to call:
>                                                 template(what? , what?,
>                                                         globals(),
>                                                         myvarname=3)

Well, assuming that the MyInstance acquires, then you want
something like:

         return template(self, globals(),
                         myvarname=determined_result,
                         some_name='hello')

Document templates have two positional arguments, the 'client'
and a mapping object.  Both can be ommitted, but if the mapping object
is provided, the client must be also.  In this case, you want to pass
'self' as the client so that the document template can get at acquired 
attributes.

Jim

--
Jim Fulton           mailto:jim@digicool.com
Technical Director   (540) 371-6909              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.