collective.listingviews:how to use custom fields to display dexterity based image field and richtext field

StackOverflow https://stackoverflow.com/questions/21204827

  •  29-09-2022
  •  | 
  •  

Question

I'd like to use the collective.listingviews controlpanel to display an image and richtext field. I have the image field working but would like to know if there is a simpler way to retrieve the image. When I try to retrieve the richtext field I end up with a permissions error.

The details:

I have a custom dexterity content type (examplecontent) and a collection which retrieves these examplecontent types.

To display the content types I've created a custom 'listingview' for the collection, the goal is that for each retrieved item the following should be displayed:

  • A RichText Field named 'body'
  • An Image Field named 'screenshot'

This is a mockup of how the layout might behave: mockup of layout

To retrieve the image field I'm using the custom tal expression:

python:"<img src='%s/view/++widget++form.widgets.screenshot/@@download' />" % item.getObject().absolute_url()

To retrieve the body field I'm using the custom tal expression:

python:item.getObject().body

The image field is working but the richtext field gives the following:

RichTextValue object. (Did you mean .raw or .output?)

When I change the tal expression for the richtext field to the following:

python:item.getObject().body.output

I then get the following permissions error:

Insufficient Privileges You do not have sufficient privileges to view this page. If you believe you are receiving this message in error, contact the site administration.

Was it helpful?

Solution

First off, you should change

python:"<img src='%s/view/++widget++form.widgets.screenshot/@@download' />" % item.getObject().absolute_url()

to:

python:"<img src='%s/view/++widget++form.widgets.screenshot/@@download' />" % item.getURL()

Since this way means you don't have to get the full object. Note the use of the getURL() method.

For the second expression, try something like this:

item/getObject/@@text-transform/body

or

python: item.getObject().restrictedTraverse('@@text-transform/body')

untested

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top