Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Only show the image from $content

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

Page: 1
Go to End
Author Topic: 999 Views
  • jeroeng
    Avatar
    Community Member
    2 Posts

    Only show the image from $content Link to this post

    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) ?

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Only show the image from $content Link to this post

    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.

  • jeroeng
    Avatar
    Community Member
    2 Posts

    Re: Only show the image from $content Link to this post

    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!.

    999 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.