[Zope] question about displaying object content in page template

Andras Frankel Andras.Frankel at ec.gc.ca
Tue Aug 24 16:06:57 EDT 2004


> > I created a page_template called index_html in PageLayout, whose goal is
> > to iterate through the object names in ModNames and display the content of
> > their "MyContent".  Here is the code:
> > 
> > <ul>
> > <span tal:repeat="item template/ModNames">
> > <li tal:content="item"></li>
> > <span tal:define="file python:'/root/SSS/priv/' + item"
> >       tal:condition="exists:file/MyContent"
> >       tal:replace="structure file/MyContent"></span>
> > </span>
> > </ul>
> > 
> > Now, that doesn't work.  Zope believes that file/MyContent doesn't exist, even 
> > though it does.  I tried displaying the value of the 
> > attribute/variable (?) "file"
> 
> It's a variable that you defined.
> 
> > , and it indeed is 
> > /root/SSS/priv/<some_object> which is correct.
> 
> Ah, but it's a string.
>      
> > Can somebody tell me what's wrong and help me how to fix this?
> 
> You have created a path, "/root/SSS/priv/foo"
> and IIUC you want to show the content of the object at that path.
> The path is just a string and you need to resolve it to an object.
> Try something like this:
> 
>   <span tal:define="file_path python:'/root/SSS/priv/' + item;
>                     file python:container.restrictedTraverse(file_path)"
>         tal:condition="exists:file/MyContent"
>         tal:replace="structure file/MyContent"></span>
>  </span>

Thank You.  I get it now: Zope differentiates between a string and a path
object.  

Your code works.  The only difference is that it doesn't need the
prefix '/root' inside file_path.

Thanks again, 

Andras




More information about the Zope mailing list