Skip to content

Lawtec

Sections
Personal tools
You are here: Home Members antonh's Home Getting more out of the portal_catalog
Document Actions

Getting more out of the portal_catalog

by antonh last modified 07-Sep-06 11:48 AM

I decided thismorning that I didn't like the way readers of this site (is there anyone out there?) would have to click on the article title to read the full contents. I wanted it on the front page. Trying to make that happen taught me a few things about how the portal catalog, and the "ZopeZen":http://zopezen.org skin work.

My first attempt was to simply copy and past the bit from newsitem_view which displays the body of a document. So I cut and pasted the following into the news template:

<p tal:content="structure item/CookedBody">
   News Item body.
</p>

But it didn't work. I got a KeyError. It confused me for a while - saw a few people having the same problem, but not getting a response on the newsgroups. That is usually a sign that you are doing something silly.

Then I realised that 'item' wasn't necessarily what I thought it was. Rather than being the object, it was a catalog query result. Thus it would only have attributes corresponding to those indexed by the catalog (which of course doesn't include the body because it would be too big and make searches too slow). Bit more reading and I came up with this:

<p tal:content="structure python:item.getObject().CookedBody()">
News Item body.
</p>

But that came up with an attribute error as well. So, what was going on? Well, on closer introspection I realised that I was getting the results from a script in the ZopeZen skin called getNewsAndReplies. One look at that, and I discovered that I this script wasn't returning catalog results, but a dictionary!. So I added item.getObject().CookedBody() to the dictionary (one extra line in the script), and changed back to the first version of the template. And it worked :)

 


This site conforms to the following standards: