----- Original Message ----- 
From: "Dieter Maurer" <[EMAIL PROTECTED]>
To: "Li Dongfeng" <[EMAIL PROTECTED]>
Cc: "Zope" <[EMAIL PROTECTED]>
Sent: Wednesday, September 20, 2000 3:25 AM
Subject: Re: [Zope] Strange CSS inclusion BUG


> Li Dongfeng writes:
>  > To use CSS file, I put the following line in the head of HTML files:
>  > 
>  >     <dtml-if local_css>
>  >     <link href="<dtml-var "local_css.absolute_url()">"
>  >           rel="stylesheet" type="text/css">
>  >     </dtml-if>
>  > 
>  > Where "local_css" is a DTML document containing CSS style sheet.
>  > But the DTML generates the following error message:
>  > 
>  >     Error Type: AttributeError
>  >     Error Value: 'string' object has no attribute 'absolute_url'
>  > 
>  > If I strip the <dtml-if  protection, the code works OK.
>  > Why is the DTML document local_css changed into a string 
>  > after <dtml-if>?
> That is a dtml-if caveat!
> 
>   The dtml-if documentation says that dtml-if caches its
>   variable value to save time, in case the variable is
>   in fact a function that takes long to call.
> 
>   What happens in your case:
>     <dtml-if local_css> looks up "local_css" and because
>     it is callable, it gets called (i.e. rendered).
>     The result is a string. This string is bound to
>     "local_css" inside the <dtml-if>...</dtml-if>.
>     Therefore, "local_css.absolute_url" results in
>     the error you observed.
> 
> You can replace <dtml-if local_css> by
> <dtml-if "_.has_key(local_css)">.
> 

This really works! Even when the request is from a folder
below where local_css resides. This success sugests that
"_.has_key()" also use aquisition to search for objects.

> This will not be equivalent to "<dtml-if local_css>" but
> good enough for your purpose.
> 
> If you want to emulate it more faithfull, you could
> use:
> <dtml-if "_.has_key(local_css) and _['local_css']">
> 
> This is equivalent ot "<dtml-if local_css>" with the
> exception of the caching.
> 
> 
> Dieter

_______________________________________________
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )

Reply via email to