[Zope] ZPT reading a file

J Cameron Cooper jccooper at jcameroncooper.com
Fri Nov 28 19:35:33 EST 2003


Jay Dorsey wrote:

>This is probably a simple task, but its giving me a heck of a time.  
>
>I've got a folder with some files in it.  I'm using a PageTemplate to
>loop through the folder and pull the attributes of the templates out.
>I've got something like this:
>
><div tal:repeat="item sorted_objects">
>	<div tal:content="item/title">title here</div>	
>	<div tal:content="item/title">author here</div>	
>	<div tal:content="structure item">content here</div>	
></div>
>
>The PageTemplates originally contained HTML, but I'm not so 
>stuck on it that I can't use Structured Text instead (it doesn't 
>seem to me that there is an html option for tal:content tags). 
>Regardless of whether I use "structure" or "text", the content 
>comes back as text when I view the page.
>
You're all over the map terminologically, so I'm not sure that I can 
tell what you actually mean. Still:

I'm assuming that 'sorted_objects' is defined previously by something 
like a sequence.sort() on the 'objectValues' of your Folder.

I did a test of this with a folder 'ddd' containing some PageTemplates 
and Files containing fragmentary HTML. This worked fine::

<div tal:repeat="item here/ddd/objectValues">
    <div tal:content="item/id">id here</div>   
    <div tal:content="item/title">title here</div>   
    <div tal:content="structure item">content here</div>   
</div>

Notice that it's almost exactly what you wrote. The contents of the 
'item' objects are output exactly as contained, which means the HTML 
renders. Remove the 'structure' keyword and the HTML is escaped and 
viewable on the page. (You are aware of the exact function of 
'structure' right?) Now, if you want to render Structured Text (as 
contained in a File) you have to say something like::

<div tal:define="pss modules/Products/PythonScripts/standard" 
tal:content="structure python:pss.structured_text(item)">

>I'm assuming this is because I'm accessing the item incorrectly.
>
>What would be the easiest way to get the content out of each item 
>and use either structured text or just keep the HTML as well?
>
>Zope is just killing me right now--if this was plain ol' python I 
>would have a look at dir(item) to see if there was a  special 
>attribute or method I needed. Thankfully I'm just learning zope on
>my own time, else I'd feel horribly useless instead of only 
>terribly so ;-)
>
DocFinder (Or DocFinderEverywhere) may be of help here. You can, by the 
way, get a Python console into a live Zope. If you get 'zctl' or Zope 
2.7 (which comes with 'zopectl' which is pretty much the same) you can 
just pass that script a 'debug' and off you go.

>The documentation seems lacking on the website, and on the net in 
>general, as far as basic "heres how you do X" goes.  Zopelabs is 
>good, and one or two other sites I've found, but I know this 
>has to be a really easy task.  I appreciate any assistance.
>
I suspect that this is well covered and you're just doing something 
trivially wrong or misunderstanding something (perhaps the way 
'structure' works). But in any case, one can't cover everything you 
might try to do. That's an awfully big space, even among "simple" tasks.

                --jcc





More information about the Zope mailing list