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

Global Variable For Background Image


Go to End


5 Posts   2606 Views

Avatar
steve_nyhof

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,
Steve

Avatar
tobych

Community Member, 97 Posts

27 December 2009 at 3:45pm

Edited: 27/12/2009 3:46pm

Steve,

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() {
		parent::init();
		Requirements::themedCSS("layout"); 
		Requirements::themedCSS("typography"); 
		Requirements::themedCSS("form"); 
		Requirements::css($this->themeStyleSheet());
	}

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

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

Avatar
steve_nyhof

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.

Avatar
tobych

Community Member, 97 Posts

28 December 2009 at 4:56pm

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

Toby

Avatar
steve_nyhof

Community Member, 224 Posts

29 December 2009 at 2:43am

Hi Toby,
See this post...
http://silverstripe.org/content-editor-discussions/show/262452?start=8#post276050

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.