question about displaying object content in page template
Hello, I would like to ask for help concerning page templates. I created two classes. First one is called "CatPageTemp", and it has the property "MyContent" of type TextArea. MyContent contains HTML encoded text. The second class is called "PageLayout", and has a property called "ModNames" of type tokens. ModNames contains a list of objects of type CatPageTemp that reside in folder /SSS/priv. Note that the folder name is not explicitly stored in ModNames. 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", and it indeed is /root/SSS/priv/<some_object> which is correct. Can somebody tell me what's wrong and help me how to fix this? Thanks. Andras PS: I am ready to give clarifications if this post is not clear enough.
On Tue, Aug 24, 2004 at 05:47:48PM +0000, Andras Frankel wrote:
Hello,
I would like to ask for help concerning page templates.
I created two classes. First one is called "CatPageTemp", and it has the property "MyContent" of type TextArea. MyContent contains HTML encoded text.
The second class is called "PageLayout", and has a property called "ModNames" of type tokens. ModNames contains a list of objects of type CatPageTemp that reside in folder /SSS/priv. Note that the folder name is not explicitly stored in ModNames.
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> -- Paul Winkler http://www.slinkp.com
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
participants (2)
-
Andras Frankel -
Paul Winkler