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.

Template Questions /

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

Changing background on each page without tons of templates


Go to End


26 Posts   13403 Views

Avatar
Friizu

Community Member, 17 Posts

1 June 2016 at 3:50am

Edited: 01/06/2016 4:03am

Root.Main will make ur upload field to main tab Root.Content.Backround will make u new tab called Background.

Still i can't understand ur extends to EnquiryPage try to extend Page instead (if that works u can change). also don't forget to run /dev/build?flush=all after code changes.

Avatar
mhdesign

Community Member, 216 Posts

1 June 2016 at 9:16am

Root.Content.Background is deprecated but Root.Background works! Woohoo!

Thanks for the help Friizu -- I realise that this would work just as well if I had this code on Page.php, however I only want to change background images on landing pages, this is why I've associated it with this page type.

So, for the record, the working code is:

<?php
/**
 * Defines the LandingPage page type
 */
 
class LandingPage extends EnquiryPage {
   static $db = array(
  );   
  static $has_one = array( 
     'Background' => 'Image' 
  );

function getCMSFields() {
		$fields = parent::getCMSFields();
		// add the upload control for the background image to the cms 
		$fields->addFieldToTab("Root.Background", new UploadField('Background'));
		 return $fields;
	}
}

class LandingPage_Controller extends EnquiryPage_Controller {     
}

cheers!!

Go to Top