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

Global Variable For Background Image

Go to End

5 Posts   2484 Views


Community Member, 224 Posts

26 December 2009 at 3:29pm

I have read some topics on global values or variables. Something about adding a home page.

Here is what i am trying to do...

I have 20 different background images in separate folders (at the moment) that my clients can select from. Currently I have them dragging the one being used out of a "Backgrounds" folder, then dragging another with the same name from another folder into the Backgrounds folder.

I have a Header Images tab in my editor to upload images for a specific page, but i am looking to upload a background image file to show for the whole site.

Does anyone have some ideas, and examples please?

Thank you,


Community Member, 97 Posts

27 December 2009 at 3:45pm

Edited: 27/12/2009 3:46pm


I'm confused. Is this a question about SilverStripe, about CSS, or about your particular editor?

Assuming for now that's it's about SilverStripe, if you want clients to be able to choose a background image in the CMS, one way is to add a field to your HomePage page type. Then add code in your Page_Controller to pull in an appropriate CSS file. Each CSS file would have perhaps just the one line specifying the background image by accessing this field in the template. You could instead preprocess a single CSS file based on the value.

I recently added some functionality similar to this for a client. The code looked something like this:

class HomePage extends Page {
  public static $db = array(
				'ThemeStyle' => "Enum('default, beige_red, blue', 'default')"

  function getCMSFields() {
    $fields = parent::getCMSFields();
    $themeStyleField = new DropdownField('ThemeStyle', 'Theme Style', singleton('HomePage')->dbObject('ThemeStyle')->enumValues()
    $fields->addFieldToTab('Root.Content.SiteConfiguration', $themeStyleField);
    return $fields;


class Page_Controller extends ContentController {
	public function init() {

	function themeStyleSheet() {
	  $themeStyle = $this->getHomePage()->ThemeStyle;
	  return "themes/mytheme/css/styles/$themeStyle.css";

	function getHomePage() {
	  return DataObject::get_one('HomePage');


Community Member, 224 Posts

27 December 2009 at 5:17pm

Thank you for this.

I am working through a similar thing with a global variable set on it's own global tab, and requires the Home Page. The problem I am facing is that I am unable to get the Home Page to show up in the Bahaviors tab.

I will work through your code and see if I am missing something.


Community Member, 97 Posts

28 December 2009 at 4:56pm

Feel free to show us your code. Or try the IRC channel.



Community Member, 224 Posts

29 December 2009 at 2:43am

Hi Toby,
See this post...

I am on a time frame to get this working in just few days.

I may go back to the start as SilverRay says on a test setup and see where I am going wrong.