我正在开发自定义 portlet,我正在尝试确定了解集合返回的内容项是否具有特定标签/关键字的最佳方法。收集结果是否暴露了这些数据?如果是这样,我如何从我的门户页面模板访问它。如果没有,我必须定制什么才能让它暴露出来?我希望能够将特定的 css 类添加到具有特定关键字/标签的项目。
换句话说:
有没有像 item.getSubject()
那样可以返回所有关键字或 item.hasSubject("foo")
的东西?
更新: @Giacomo - 我试过了,但没有意识到 Subject 是一个元组。我能够通过以下方式在模板中获得预期的结果:
<dd class="portletItem"
tal:define="featured python:' featured' if 'feature' in obj.Subject else '';"
tal:attributes="class python:oddrow and 'portletItem even'+ featured or 'portletItem odd' + featured">
feature 是我在内容项上输入的标签,.featured 是添加到 portlet 项的 css 类。我是 Plone 的新手。是否有全面的在线文档,您可以在其中搜索源代码树(类、方法等),或者我是否坚持使用 grep 来搜索内容?
最佳答案
您可以访问集合结果,它们只是目录大脑,例如:
for i in context.queryCatalog():
print i.Subject
如果您的模板没有直接在集合上注册,您只需将 context
替换为实际的集合名称
关于collections - Plone 4 : How to retrieve the item category/tags/keywords inside a page template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7654855/