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 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
        <dtml-if "_.has_key(local_css) and _['local_css']">

This is equivalent ot "<dtml-if local_css>" with the
exception of the caching.


Zope maillist  -  [EMAIL PROTECTED]
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to