如何在列表视图中显示基于 Dexterity 的 Plone 内容类型的图像?
在列表视图中显示基于 Dexterity 的 Plone 内容类型的图像的最佳方式是什么?
假设我有一个包含基于敏捷性的内容对象的文件夹,该对象提供图像字段,并且我想将这些对象(作为目录大脑)与其图像一起列出。可以通过调用绝对 URL 来显示列表中的图像:
<img src="" tal:attributes="src string:${item/getURL}/@@images/image/thumb" />
不过,如果图像不存在,Plone 会引发错误,并且我没有找到检查图像是否存在于页面模板中的好方法。我们显然不想唤醒列表中的对象来查找图像。
我是否必须在目录中创建图像元数据列,或者是否有我没有看到的更好的解决方案?
What's the best way to show the image of a Dexterity-based Plone content type in a listing view?
Say I have a folder with Dexterity-based content objects that provide an image field and I want to list the objects (as catalog brains) together with their image. It is possible to show the images in the listing by calling their absolute URL:
<img src="" tal:attributes="src string:${item/getURL}/@@images/image/thumb" />
Though, Plone will raise an error if the image does not exist and I don't see a good way to check if the image exists in a page template. We obviously do not want to wake up the objects for a listing, to look up the image.
Do I have to create an image metadata column in the catalog or is there a better solution I don't see?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只要正确批处理,我就不会太担心唤醒列表中的对象。如果您使用 plone.app.textfield 和 plone.namedfile 中的字段,则大数据将保存在单独的持久对象中,因此主要内容项对象相对较轻。当然,如果您想确保它不会对您的情况造成损害,请自行进行基准测试。
I wouldn't worry too much about waking up objects in a listing as long as it's properly batched. If you're using the fields from plone.app.textfield and plone.namedfile then large data is kept in separate persistent objects, so the main content item object is relatively lightweight. Of course, do your own benchmarking if you want to be sure it doesn't hurt for your case.
有一个关于如何在专业Plone 4开发中执行此操作的秘诀(我相信第10章)。不幸的是,我真的不记得现在该怎么做。 :)
There is a recipe for how to do this in Professional Plone 4 Development (chapter 10, I believe). Unfortunately, I genuinely can't remember how to do it right now. :)
在 Portal_catalog 中创建元数据,您将在其中存储有效图像的路径。
创建一个同名的 python 脚本,用于检查对象是否有图像,如果没有图像,则返回默认图像。
Create a metadata in portal_catalog where you will store a path to a valid image.
Create a python script of the same name that will check if the object has an image and in the case there is no image, return a default one.
检查图像字段的示例可用:
A example for checking image field is avalable: