Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Multiple Images Per Page

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1368 Views
  • arsenic
    Avatar
    Community Member
    9 Posts

    Multiple Images Per Page Link to this post

    I need to associate multiple images with a page. Do I use has_many Image on the page? Or do I use has_many DataObject on the page where the DataObject has_one Image? What's the best way to do this?

  • marblegravy
    Avatar
    Community Member
    19 Posts

    Re: Multiple Images Per Page Link to this post

    I think it depends on how many images you need and how you plan on displaying them.

    If all you want is a Gallery style setup, then setting up a new DataObject for the page would be your best bet (of go check out the Gallery Module...). The SS Book has a good demo you can adjust easily using Jobs and Job Categories... I'm sure there's a similar tutorial around here somewhere.

    If you have set places you want them all to go, you might want to consider just setting up individual fields for each item on the Page and coding their placeholders in to the layout.

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Multiple Images Per Page Link to this post

    Like marblegravy said, it depends how you want to display them. If you literally just want to relate many images, then $has_many is fine and i would use something like: http://doc.silverstripe.org/doku.php?id=modules:DataObjectManager#imagedataobjectmanager to manage them

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Multiple Images Per Page Link to this post

    I want to display a gallery of images per product & a main image. I have;

    class Product extends DataObject
    {
       static $db = array (
          'Name' => 'Text'
       );
       
       static $has_one = array (
          'image1' => 'Image',
       );
       
       static $has_many = array (
          'gallery' => 'Image'
       );
          
       public function getCMSFields_forPopup()
       {
          $fields = new FieldSet(
             new TextField('Name'),
             new ImageField("image1","Main image",null,null,null,"assets/myFolder/"),   
          );

          $fields->push(new ImageField("gallery","Image gallery",null,null,null,"assets/myFolder/"));

          return $fields;
       }
    }

    The upload/attach for the main image is fine, but in the popup 'Image gallery' appears as a single File upload.

    Any ideas?

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