the_jay
(Johnny Wezel)
March 5, 2025, 9:32pm
1
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.
alert
(Alessandro Pisa)
March 6, 2025, 8:09am
2
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.
yurj
(Yuri)
March 6, 2025, 10:51am
3
the_jay:
RepeatItem
RepeatItem returns the object when called.
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from __future__ import annotations
import copy
import re
from chameleon.exc import LanguageError
This file has been truncated. show original
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"
.
the_jay
(Johnny Wezel)
March 6, 2025, 1:55pm
5
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
yurj
(Yuri)
March 6, 2025, 3:28pm
6
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