[Zope] Question: Passing variables several levels

Michel Pelletier michel@digicool.com
Sat, 04 Sep 1999 03:10:34 -0400


John Goerzen wrote:
> 
> OK, Here's the story.  I have several cases in which I'd like to have
> a horizontal bar.  So, I defined a DTML method at the top of the
> hierarchy named Banner_Bar_Generic.  This works in isolation.  Then, I
> have a DTML method named linkHome that generates a relative link
> containing a sufficient number of "../" entries to take the user back
> to the top of the site.  This also works in isolation, but oddly
> enough, only when called as <dtml-var linkHome>, and not as <dtml-var
> "linkHome">; the latter apparently has problems passing PARENTS or
> REQUEST.

This is because linkHome is a callable object and is not being called:

  <dtml-var "linkHome()">

will call linkHome, but not how you want it to.  To call a method
explicitly, you must pass in a context in which the method can render
itself.  This means:

  <dtml-var linkHome>

is the same as 

  <dtml-var "linkHome(this(), _)">

> linkHier (not shown; also works in isolation and has an
> implementation similar to linkHome) generates a strong showing where
> the person is in the site; ie "Air Capital Linux Users Group:
> Information: Free Software", in a Yahoo fashion.
> 
> Now, the question.  I want to put a top bar on each page, containing
> these sorts of links.  So, I figure I ought to define a
> Banner_Bar_Top, implemented in terms of Banner_Bar_Generic.  However,
> I can't figure out how to pass along the proper strings; I always get
> a Zope error.  Here's my latest attempt at this.  Also below is the
> code for the other DTML methods.  Any suggestions are welcome!
> 
> *** Banner_Bar_Top:
> 
> <dtml-with REQUEST>
> <dtml-with PARENTS>
> <dtml-with "_.namespace(StopAt='ACLUG')">
>   <dtml-var "Banner_Bar_Generic(
>             ltext='<FONT FACE=' + 'helv,helvetica,arial' + '>'+
>             linkHier + '</FONT>',
>             rtext='<A HREF=' + linkHome + '><FONT COLOR=#FFFFFF>Home</FONT></A>',
>             bgcolor='#9C0000')">
> </dtml-with>
> </dtml-with>
> </dtml-with>
> 

Take out the two outer withs, you don't need them, just add some context
to Banner_Bar_Generic:

<dtml-var "Banner(this(), _, ltext=... rtext=...)">

-Michel