Plon 4:如何检索页面模板内的项目类别/标签/关键字
我正在开发一个自定义 portlet,并试图确定了解集合返回的内容项是否具有特定标签/关键字的最佳方法。收集结果会暴露这些数据吗?如果是这样,我如何从我的门户页面模板访问它。如果没有,我需要定制什么才能将其公开?我希望能够向具有特定关键字/标签的项目添加特定的 css 类。
换句话说: 有没有什么东西可以像 item.getSubject()
一样返回所有关键字,或者 item.hasSubject("foo")
?
更新: @Giacomo - 我已经尝试过,但未能意识到主题是一个元组。我能够在模板中实现所需的结果,如下所示:
<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 是添加到的 css 类portlet 项目。我是克隆新手。是否有全面的在线文档,您可以在其中搜索源代码树(类、方法等),或者我是否坚持使用 grep 来搜索内容?
I am working on a custom portlet and I'm trying to determine the best way to know whether a content item returned by a collection has a particular tag/keyword. Do the collection results expose this data? If so, how do I access that from my portal's page template. If not, what would I have to customize in order to have it be exposed? I want to be able to add a particular css class to items with a certain keyword/tag.
In other words:
Is there anything that would work like item.getSubject()
which would return all keywords, or item.hasSubject("foo")
?
Update: @Giacomo - I had tried that, but failed to realize that Subject was a tuple. I was able to achieve the desired result in the template with something like:
<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">
where feature is the Tag I enter on the content items, and .featured is a css class added to the portlet item. I am new to Plone. Is there comprehensive online documentation where you can search the source tree (for classes, methods, etc) or am I stuck with using grep to search for things?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以访问集合结果,它们只是目录大脑,例如:
如果您的模板没有直接在集合上注册,您只需将
context
替换为实际的集合名称you can access collections results and they are just catalog brains, for example:
if your template is not directly registered on collections you just need to replace
context
with the actual collection name