How to show Plone content type image in list view?

What is the best way to show an image of a Plone content type in a listing view?

Let's say I have a folder with Dexterity-based content objects that provide an image field, and I want to list the objects (like the brains of a directory) along with my image. You can display images in a list by calling their absolute URL:

<img src="" tal:attributes="src string:${item/getURL}/@@images/image/thumb" />

Although, Plone will throw an error if the image does not exist, and I don’t see a good way to check if the image exists in the page template. Obviously, we don’t want to wake the objects for printing in order to see the image.

Do I need to create an image metadata column in a directory or is there a better solution that I don't see?

+5
source share
4 answers

I would not worry too much about waking up objects in a listing if it is properly packaged. If you use fields from plone.app.textfield and plone.namedfile, then the big data is stored in separate permanent objects, so the main object of the content element is relatively light. Of course, do your own benchmarking if you want to be sure that it won’t hurt your business.

+5
source

There is a recipe for how to do this in Professional Plone 4 Development (chapter 10, I think). Unfortunately, I really don’t remember how to do it right now. :)

+4
source

portal_catalog, . python script , , , .

0
source

An example of checking the image field is available:

class product(grok.View):
    grok.context(IDexterityContent)
    grok.require('zope2.View')
    grok.name('view')

    def update(self):
        """
        """
        # Hide the editable-object border
        context = self.context
        request = self.request
        request.set('disable_border', True)


    #brain come from contained image field  object
    def isImageAvalable(self,brain=None):
        """判断图片字段是否有效"""
        try:
            if brain is None:
                image = self.context.image.size
            else:
                 image = brain.getObject().image.size

            return (image != 0)

        except:
            return False
0
source

All Articles