21280 Posts in 5729 Topics by 2600 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1683 Views |
-
Global Variable For Background Image

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 -
Re: Global Variable For Background Image

27 December 2009 at 3:45pm Last edited: 27 December 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');
}
} -
Re: Global Variable For Background Image

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.
-
Re: Global Variable For Background Image

28 December 2009 at 4:56pm
Feel free to show us your code. Or try the IRC channel.
Toby
-
Re: Global Variable For Background Image

29 December 2009 at 2:43am
Hi Toby,
See this post...
http://silverstripe.org/content-editor-discussions/show/262452?start=8#post276050I 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.
| 1683 Views | ||
|
Page:
1
|
Go to Top |

