Re[2]: [Zope-CMF] Default View for folderish classes and index_html

Tres Seaver tseaver@zope.com
19 Jun 2002 09:50:15 -0400


On Wed, 2002-06-19 at 04:01, Rainer Thaden wrote:
> Dieter,
> 
> 
> DM> Rainer Thaden writes:
> DM>  > i built a class ('fold_class') derived from PortalFolder, PortalContent
> DM>  > and DefaultDublinCoreImpl (in that order).
> DM>  > 
> DM>  > When I add an image to the instance ('inst') of the folderish class in
> DM>  > .../temp/inst/img1 and provide some HTML-Code in an attribute of the
> DM>  > class which references to the image like 'bla bla <img src='img1'>',
> DM>  > everything is fine if I call the view method ('fold_class_view') from
> DM>  > the actions box in the view of the class instance which displays the
> DM>  > HTML code together with the image. 
> 
> DM> You need to set a base tag (method "setBase" of object "RESPONSE").
> 
> Thanks a lot. You helped me again.
> I now use the following code in the view:
> 
> <html ...>
> <body>
>  ...
>  <div metal:fill-slot="header">
> 
>   <span tal:define="base here/absolute_url;
>                     dummy python:request.RESPONSE.setBase(base)">
>   </span>
>  </div>
>  ...
>  
> This may not be very elegant, but it works.
> However, when I put the <span> tag in the <html> or <body> tag, it
> does not work and I'm not quite sure why.

The contents of the <html> and <body> tags are replaced by METAL
(the macro substitution language) before TAL gets a chance to evaluate
them.  Only markup which is inside the slots will remain after macro
expansion.

The standard 'main_template' in the CMF actually defines a special,
empty slot for this purpose::

 <head>
  <title tal:content="here/expanded_title"> Title goes here </title>

  <metal:block define-slot="base" /> 

  <link rel="stylesheet" href="zpt_stylesheet.css" type="text/css"
        tal:attributes="href here/zpt_stylesheet/absolute_url">

 </head>

To use the slot, your code could just fill it with the appropriate
<base> tag, e.g. the stock 'document_view' does this::

  <html...>
  <head>
   <metal:block fill-slot="base">
       <base href=""
             tal:attributes="href python: here.absolute_url() + '/'" />
   </metal:block>
  </head>

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com