Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Only show the image from $content

Go to End

3 Posts   1442 Views


Community Member, 2 Posts

22 February 2010 at 11:29pm

Edited: 22/02/2010 11:41pm

Hi there,

first, i'm new to silverstripe, i want to use it for a simple website for my client.

The website has 2 templates;

1) list of items ($title)
2) item overview ($title, $content)

The content of an item is text, and several images (added with TinyMCE in the content field).

Nothing really excited, and got it working in a few hours.

But now the problem/question; I want to include an image as a thumbnail in the list-view. Is it possible to extract the first image (or even a random) that is inserted in the $content and show it as a thumbnail in the list view?

For example $content->$image(1) ?


Community Member, 904 Posts

23 February 2010 at 1:52am

Hi and welcome to the Forums

If I were you, I would add the images using a one-to-many relation.
This can easily be done using the DataObjectManager module. Since you would then have the images as separate DataObjects, it would be much simpler to get one of them.

Otherwise you would have to parse the HTML Content and search for images there. Also possible, but not very nice.


Community Member, 2 Posts

23 February 2010 at 2:03am

Edited: 23/02/2010 2:09am

I managed to get it working with a one-to-many, and it's super-easy to do. Now I need to consider 2 possibilities.

1) use a one-to-many

  • Pro: Possible the best way to do it in Silverstripe.
  • Con: The content-editor needs to fill an extra form when submitting data

2) use a hard coded str_replace on the $content

  • Pro: The content-editor doesn't need to fill in an extra form when submitting data
  • Con: Not so nice coding, and probably a bit buggy

Anyway, thanks for the suggestion!.