[Zope] ZPT reading a file
J. Cameron Cooper
jccooper at jcameroncooper.com
Fri Dec 5 21:12:13 EST 2003
Jay Dorsey wrote:
>On Fri, Nov 28, 2003 at 06:35:33PM -0600, J Cameron Cooper wrote:
>
>
>>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.
>>>
>>>
>>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 gave the above a shot, I got either a blank page (when the
>content was structure), or escaped HTML (when the content isn't
>specified) which shows the item type and name (i.e.
><ZopePageTemplate at 2003_11_17_06_56>). The entire code is:
>
><span tal:define="objects container/blog_entries/objectValues;
> sort_on python:(('date', 'cmp', 'desc'),
> ('title', 'nocase', 'desc'));
> sorted_objects python:sequence.sort(objects, sort_on)">
>
> <div
> tal:repeat="item sorted_objects"
> style="border:1px dashed #C0C0C0;padding:5px;margin:5px;"
> tal:attributes="id item/id">
> <h3 tal:content="item/title" style="margin-top:0px;margin-bottom:0px;">title</h3>
> <div style="font-size:xx-small;margin-left:10px;margin-bottom:10px;">posted by <a tal:content="item/author">author</a> on <a tal:content="item/date">date</a></div>
> <div
> tal:define="pss modules/Products/PythonScripts/standard"
> tal:content="structure python:pss.structured_text(item)">content goes here</div>
> </div>
></span>
>
>
If the things you're trying to include (the objects under 'blogEntries')
contain HTML (whether or not they are ZPTs or Files) the above will work
so long as the last div is::
<div tal:content="structure item">content goes here</div>
I know, because I tried it myself. If you want your content to be in
STX, then you should put that text in Files (text/plain so you can edit
them, but it doesn't really matter) in blogEntries and use exactly the
code you gave above. I don't think ZPTs are a proper container for STX:
it might work , but I didn't try it. Again, I did this, so if it doesn't
work, you're doing something non-standard outside of this. I can provide
you an export file with my structure in it if you still can't get it to
work.
>>>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.
>>
>If I understand how structure works properly, the text in the included file
>(in my example) was written using structured text, so when its output it should
>convert the text to HTML (**this** becomes <b>this</b>). I didn't realize that
>it would apply to HTML as well.
>
>
The 'structure' keyword has nothing to do with structured text: it has
to do with document structure. If what you're bringing into the document
contains layout structure (HTML) then you say "structure". Read the
description of 'tal:replace" in the Zope online help for the official
take. So: HTML (which is not intended to be viewed as such by the user)
requires 'structure' so as not to be escaped.
--jcc
--
"My point and period will be throughly wrought,
Or well or ill, as this day's battle's fought."
More information about the Zope
mailing list