Daniel Hernández
Daniel Hernández

Reputation: 1317

How to print attributes of related objects in zope templates?

I wrote an dexterity type with a field relating to another object:

institution = RelationChoice(
    title=_(u"Institution"),
    source=ObjPathSourceBinder(
        object_provides=IInstitution.__identifier__
    ),
)

And also in the template I wrote:

<span id="institution" tal:content="context/institution" />

But it prints:

<z3c.relationfield.relation.RelationValue object at 0xe3a032c>

I have tried to get attributes to build a link to the item, but the next doesn't works:

<span id="institution" tal:content="context/institution/absolute_url" />

How can I get the attributes of the objecto to make a link to it?

Upvotes: 2

Views: 253

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1124718

Reference objects are documented in the Dexterity developer manual. You are looking for the to_object attribute:

<span id="institution" tal:content="context/institution/to_object/absolute_url" />

which would insert the URL of the linked object, or you could show the Title instead:

<span id="institution" tal:content="context/institution/to_object/Title" />

Upvotes: 3

Related Questions