[triangle-zpug] partial write up of last night's plone jam

Rob Lineberger rob_lineberger at med.unc.edu
Thu May 8 16:03:00 UTC 2008

Rob had a need to browse content from a page template and wanted to use
the ATReferenceBrowserWidget to do so. Getting ATReferenceBrowserWidget
to work in an AT schema is straightforward. In fact, in a tip that
newcomer Jonathan Schisler showed us, you can make all of your reference
fields into ATReferencBrowsers by setting two tagged values on the
"content" package in UML:

Tag = imports 
Value = from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget
import ReferenceBrowserWidget

Tag = default:widget:Reference
Value = ReferenceBrowserWidget

Then any reference line you draw between two classes will create a
reference field on your content type with a field name of the referenced
content type, and that reference field's widget will be an

But Rob needed to draw a widget on a page template, not on the edit tab
of a content type. So Josh Johnson pulled out some old code from his
spiffy Trac repository which went a little something like this:

Important part #1: the javascript for ATReferenceBrowserWidget:

<html metal:use-macro="here/main_template/macros/master">
    <title tal:content="template/title">The title</title>
	<metal:javascript_head fill-slot="javascript_head_slot">
	   <tal:getjs tal:define="js
		<tal:js repeat="item js">
		  <script type="text/javascript"
				  tal:condition="python:exists('portal/%s' % item)"
				  tal:attributes="src string:$portal_url/$item">

Important part #2: using ATReferenceBrowserWidget:
<metal:field use-macro="python:context.widget('otherGenelist',
mode='edit')">My Field</metal:field>

It is important to note two things about this solution.  One, it is
context dependent, so if the current context doesn't have a field in its
schema called otherGenelist the page template will barf. Two, you
shouldn't be doing this anyway.  You should really be using Zope's
formlib and use Z3 style adapters, interfaces, browser.zcml, and other
cool stuff which only ubercool people grasp.

More information about the triangle-zpug mailing list