You are not logged in Log in Join
You are here: Home » Members » jccooper » Getting at the actual objects of a ZCatalog search in Page Templates

Log in
Name

Password

 

Getting at the actual objects of a ZCatalog search in Page Templates

I love Page Templates. But problem is, the existing documentation often refers to DTML.

You may ask: "What's the problem? Doesn't a ZCatalog search return the actual items it found?" You would be wrong.

What you actually get are Pluggable Brains, a very cool name (and concept), but not the actual object. The attributes of Pluggable Brains are those that you indexed in the ZCatalog (under the MetaData tab.) So if you want an attribute of the found object that you didn't set the ZCatalog to handle to you, you'll have to find the actual object and ask it.

I also love ZCatalog, but most of the existing examples imagine you using just the meta-data stored by the catalog and the path to the object.

Easy! Pluggable Brains have a method called getObject which returns the actual object it "wraps". (They also have a getPath method, if all you want to know is where the object is.)

So in your reporting form just do this:

  <div tal:repeat="result container/your_catalog">
    <span tal:define="item result/getObject">
      <span tal:replace="item/attr">some non-cataloged attribute</span>
      <span tal:replace="result/title">the title (which is by default cataloged)</span>
    </span>
  </div>

Piece of cake! (Although it might take a while if you don't know the API. But that's what this howto is for, no?)

So that everybody else can love both of these, especially together, here's how to get at the actual objects that a ZCatalog search turns up from a Page Template document.

So What's the Problem?

How?