3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 835 Views |
-
Only show the image from $content

22 February 2010 at 11:29pm Last edited: 22 February 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) ?
-
Re: Only show the image from $content

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.
See: http://doc.silverstripe.org/doku.php?id=modules:dataobjectmanager
http://silverstripe.org/dataobjectmanager-module-forum/Otherwise you would have to parse the HTML Content and search for images there. Also possible, but not very nice.
-
Re: Only show the image from $content

23 February 2010 at 2:03am Last edited: 23 February 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!.
- Pro: Possible the best way to do it in Silverstripe.
| 835 Views | ||
|
Page:
1
|
Go to Top |


