[Zope] Re: [Archetypes-devel] accessing fields of Archetypes objects in topic_view.pt

Paul Howell paul at smoothstone.com
Thu Dec 18 10:54:11 EST 2003


At 02:21 PM 12/18/2003 +0100, you wrote:
>I want to list the content of some field of various Archetypes objects in 
>a Topic object.
>Anyone could tell me how to access the fields from topic_view.pt page 
>template for instance? I have already managed to access them from a custom 
>view template, but since I'm not a programmer, I could't figure out yet 
>how it works from another places.
>
>Thanks:
>József Jároli

It's pretty easy once you remember (or figure out) that the information you 
want from the object is likely NOT being stored in the portal_catalog as 
metadata.  So, here's all you do to add another TD to the table and display 
an AT field called "teaser"...
1. get the topic_view.pt and hit customize

2. find the line just inside the <tbody> tag where it says
<metal:block tal:repeat="match batch">

info:   That's the start of the part that grabs info from your AT (and any 
other matching objects).  But all it grabs is the metadata from the 
portal_catalog, and not your interesting field.  You need to tell it how to 
find info from your AT object by using getObject.

3. So add a line like this inside the block
         <span tal:define="matchobj match/getObject">
and add a matching
         </span>
just before the close of that </metal:block>

4.  To get your "teaser", add this line right after the one calling 
Description:
         <td tal:content="matchobj/teaser | nothing">Teaser</td>
That will grab your teaser from your object.  If there's no "teaser" field 
(as in some non-AT object), it will return nothing, but not an 
error.  Alternatively, you could replace "nothing" with " string:no teaser ".

5.  Don't forget to add a matching teaser TH up in the top of the table so 
that people know what they're looking at:
                 <th> <tal:block i18n:translate="">Teaser</tal:block> </th>

Longer term, if this might be a performance barrier, get the portal_catalog 
metadata to pick up whatever AT fields that you'll need in your Topics.
Good luck.
=Paul




More information about the Zope mailing list