TAL repeat generates objects that return the id for the title

In code like this:

<div class="row row-cols-2" tal:repeat="article container/articles">
<div class="col card m-4 p-0" style="height: 18rem; width: 18rem;">
<div class="card-header">
Header
</div>
<div class="card-body">
<h5 class="card-title" tal:content="article/title"></h5>
<p class="card-text">Some text</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</div>

the objects are not the objects in articles (in my case page templates), but RepeatItem objects. Those objects return the id for the title. This seems a clear bug to me, the RepeatItem object should proxy all attribute of the underlying object. If this behavior is intended, then how do I get to the article object, such that I can get the title attribute of it? In an other thread I saw the suggestion to call getObject on article, but that yields an error.

I suggest you to add this line to your page template:

<?python locals().update(econtext); breakpoint() ?>

Then start the instance in foreground and visit the page that renders that page template.
You should enter a pdb session.

Once there, try to inspect:

  • what container is
  • what container.articles is

You might also check adding .aq_base, e.g.:

  • container.aq_base.articles

in order to prevent acquisition to kick in.

RepeatItem returns the object when called.

container/articles

returns a folder then you've to check what is the __iter__ of a folder. If it is getIds() (which I suspect), this explain what happens.

so you've to do folder.restrictedTraverse("@@contentlisting")() to get the brains/objects.

EDIT: as in https://5.docs.plone.org/external/plone.app.contentlisting/README.html, just use tal:repeat="article container/articles/@@contentlisting".

See Folder items, sort alphabetically - #13 by espenmn Batching folder contents based on content type (Plone 6 Classic) - #5 by petschki Get first image of folder in TAL - #2 by espenmn Listing and working with Plone content objects using plone.app.contentlisting — Plone Documentation v5.2 for some examples.

The canonical way to get the real objects from a container is to call objectValues on it.

You learn this only when you read the intro to page templates.

2 Likes

I would use @@contentlisting because it has a consistent interface, you get the brain when you need the brain and real objects when you need them.

1 Like