Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Changing background on each page without tons of templates

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

Page: 1 2 3
Go to End
Author Topic: 5167 Views
  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Changing background on each page without tons of templates Link to this post

    We all had to start somewhere ....

    If this is your Background:

    $fields->addFieldToTab('Root.Content.Main', new ImageField('Background'));

    You dont't need my Image field....

    It should be there in the cms, if you've added this to Page.php

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

    You can give it a new tab by changing Root.Content.Main to Root.Content.Background

  • evsoul
    Avatar
    Community Member
    36 Posts

    Re: Changing background on each page without tons of templates Link to this post

    Where should the "background uploader" field show up?

    I tried changing it from Root.Content.Main to Root.Content.Background to see if it would make any difference and it didn't.
    Is there anything like the ?flush=1 that I need to do so that it rescans all of that Page.php file?

    I'm doing it exactly as I'm reading and not seeing any extra fields.. but maybe I'm not looking in the right place. I assume if I do the Root.Content.Background it would show up as another tab next to Main and Metadata? I did that and it doesn't show up and even tried sitename.com/admin/?flush=1 just to see.. and I tried changing it back to Root.Content.Main and do not see anything under the main tab for each page..

    Any thoughts as to what I could be doing wrong? Or where I should be looking?

    Thanks a lot!

    -Greg

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Changing background on each page without tons of templates Link to this post

    hm, could you pastie.org your code?

  • evsoul
    Avatar
    Community Member
    36 Posts

    Re: Changing background on each page without tons of templates Link to this post

    oh cool never used pastie before! very cool.

    Page.php: http://pastie.org/789234

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Changing background on each page without tons of templates Link to this post

    getCMSFields needs to be in class Page instead of class Page_Controller.

  • evsoul
    Avatar
    Community Member
    36 Posts

    Re: Changing background on each page without tons of templates Link to this post

    Awesome! See I have no knowledge of php :-/ but once my schedule opens up a bit I will try to learn some basics to start off.

    I now get the background upload field below the WYSIWYG text field but when I upload an image I get a very quick flash of some error then it goes back to the uploader field. So I tried "attach from file store" and there the image was in "uploads" directory I selected it and I get this error:

    "Website Error
    There has been an error

    The website server has not been able to respond to your request."

    in the box where the background uploader field is.

    Any thoughts?

    And thanks a lot for the help!

  • evsoul
    Avatar
    Community Member
    36 Posts

    Re: Changing background on each page without tons of templates Link to this post

    Been a few days with no reply so wanted to bump the thread if that's ok.

    Does anyone know what could cause the error:

    "Website Error
    There has been an error

    The website server has not been able to respond to your request."

    when trying to select an already uploaded background image?
    I went to the uploads directory and the image had been uploaded successfully when I viewed it.

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Changing background on each page without tons of templates Link to this post

    Website error could really mean anything....

    Check your server error logs for more information and make shure your site is in devmode.

    5167 Views
Page: 1 2 3
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.