Jump to:

22999 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Adding images to pages and silverstripe 3.1

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: 262 Views
  • nmshah
    Avatar
    Community Member
    21 Posts

    Adding images to pages and silverstripe 3.1 Link to this post

    In order to add an image to a page type, I used the following code in silverstripe 3.0 but the same code (after changing public static to private static) does not display the image in silverstripe 3.1

    In ContentPage.php

    <?php
    class ContentPage extends Page {
       private static $db = array(
       );
       private static $has_one = array(
          'Photo' => 'Image'
       );
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab("Root.Images", new UploadField('Photo'));
          return $fields;
       }
    }
    class ContentPage_Controller extends Page_Controller {}

    on ContentPage.ss

    <% if Photo %><div class="pollaroid-Blog">$Photo.SetWidth(250)</div><% end_if %>

    Am I missing something that needs to be changed to get this to work in Silverstripe 3.1

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