Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

Adding images to pages and silverstripe 3.1


Go to End


904 Views

Avatar
nmshah

Community Member, 21 Posts

4 July 2013 at 5:12pm

Edited: 04/07/2013 5:14pm

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