Jump to:

23481 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Problem adding mutiple images to 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 2
Go to End
Author Topic: 2144 Views
  • Pix
    Avatar
    Community Member
    135 Posts

    Problem adding mutiple images to page Link to this post

    Hi All,

    I have a custom page with multiple images, and everything is working fine. It's built like this right now:

    static $has_one = array(
    'Photo' => 'Image',
    'PhotoTwo' => 'Image',
    'PhotoThree' => 'Image',
    'PhotoFour' => 'Image',
    'PhotoFive' => 'Image',
    'SmallBanner' => 'Image'
    );

    The problem comes when I try to add just one more image, it blows up the site and I get "Sorry, there was a problem handling your request". I am using SS 2.4.5. Is there some sort of limit? Or a better way to do it? Or am I just missing something (besides brain cells)?

    Thanks

  • Hattori
    Avatar
    Community Member
    20 Posts
  • svandragt
    Avatar
    Community Member
    44 Posts

    Re: Problem adding mutiple images to page Link to this post

    Data Object Manager is not yet compatible with SilverStripe 3?

    [User Deprecated] DataObjectDecorator->__construct is deprecated. Use DataExtension instead. Called from ReflectionClass->newInstance.

  • svandragt
    Avatar
    Community Member
    44 Posts

    Re: Problem adding mutiple images to page Link to this post

    I just got this working, you do not need to install any module anymore in SilverStripe 3.0:

    Because the UploadField can now handle multiple files/images, we simply specify a has_many relationship and create a screenshot class that extends the Image DataObject. Remember to set a link back from the dataobject to the page type:

    In
    mysite/code/YourPage.php:

    class YourPage extends Page {

       public static $has_many = array(
          'Screenshots' => 'Screenshot'
       );

       public function getCMSFields() {
          $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Main', new UploadField('Screenshots'), 'Content');
          return $fields;
       }
    }

    class Screenshot extends Image {
          public static $has_one = array(
             'YourPage' => 'YourPage'
       );   
    }

    Then, in your theme's
    templates/Layout/YourPage.ss, we can just call the has_many relationship and use all the Image class's methods:

    <div class="content-container typography">   
       <article>
          <h1>$Title</h1>
          <div class="content">
                <% loop Screenshots %>
                   $SetWidth(320)
                <% end_loop %>
             $Content
          </div>
       </article>
          $Form
          $PageComments
    </div>
    <% include SideBar %>

  • Pix
    Avatar
    Community Member
    135 Posts

    Re: Problem adding mutiple images to page Link to this post

    Hi,

    Thanks for all the replies. That looks like a good solution. Haven't upgraded to 3.0 yet, I guess I better do that

    For now I just can't see why the current code is bombing....is there a quick and easy fix?

    Thanks

  • MartinPhone
    Avatar
    Community Member
    57 Posts

    Re: Problem adding mutiple images to page Link to this post

    Thanks for this. Still trying to get my head around what SS3 can and can't do and this example was just what I needed.

  • congii
    Avatar
    Community Member
    6 Posts

    Re: Problem adding mutiple images to page Link to this post

    Hi, this works on the CMS side, in the front-end form I can't seem to make this work using FileField.

  • mimamo
    Avatar
    Community Member
    22 Posts

    Re: Problem adding mutiple images to page Link to this post

    can someone tell me how to add a variable to get the images instead of $SetWidth ?

    2144 Views
Page: 1 2
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.