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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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


1297 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