Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Global Variable For Background Image

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1988 Views
  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Global Variable For Background Image Link to this post

    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

  • tobych
    Avatar
    Community Member
    97 Posts

    Re: Global Variable For Background Image Link to this post

    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');
       }
       
    }

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Global Variable For Background Image Link to this post

    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.

  • tobych
    Avatar
    Community Member
    97 Posts

    Re: Global Variable For Background Image Link to this post

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

    Toby

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Global Variable For Background Image Link to this post

    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.

    1988 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.