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.

Themes /

Discuss SilverStripe Themes.

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

Editing footer from within the back-end editor?


Go to End


9 Posts   6598 Views

Avatar
donall

Community Member, 7 Posts

6 November 2009 at 11:04pm

Edited: 06/11/2009 11:06pm

HI,
I am now modifying the Paddygreen theme, and I wonder how I can make the content in the footer editable from within the ordinary back-end editor. This because I would like the client to have the opportunity to change content in the footer. If I put all content in the Footer.ss-file it is locked for the client, as far as I can see.

Which steps should I take to make a footer editable?

Avatar
yurigoul

Community Member, 203 Posts

7 November 2009 at 7:05am

I asked questions about this, and got some sugestions from people. I started with the assumption I wanted to have extra fields on the homepage that would appear in the footer on every page. In the end I created a special footer page, but the basics are the same.

http://silverstripe.org/themes-2/show/271952#post271952

Must admit my starting point was all wrong - do not try to get the absolute parent, it does not work and it is apparantly too resource intensive. But there is a sugestions at the end on how to make a page undeletable and unique.

I ended with adding this to the controler of my page.php to make the function accessible to all pages that use it as a base class.

//showing footer info
public function Footer(){
$myFooter = DataObject::get_one('FooterOfPage');
return $myFooter;
}

I then used a footer.ss that I inluded in my page.ss with the code:

<% control Footer %>
$ContentforFooter
<% end_control %>

And added a nice icon (a nice 'F') to the footer page in the backend with:

static $icon = "themes/annomedia/images/icons/footer";

Avatar
donall

Community Member, 7 Posts

9 November 2009 at 12:43am

Edited: 09/11/2009 12:44am

Thanks a lot! Now I have something to dive into. I keep my breathe and jump. When I will come up again I think there will be new questions. Thank you!

Avatar
jondbaker

Community Member, 19 Posts

24 December 2009 at 9:11am

Edited: 24/12/2009 9:15am

I've tried to follow the directions in this thread to set up a CMS-editable footer, but cannot get the tab to display on the backend.
Page.php

class Page extends SiteTree {
    ....
    public static $has_one = array(
        'FatFooter' => 'FatFooter'
    );
    ...
}
class Page_Controller extends ContentController {
    ...
        public function GetFatFooter(){
            $fatFooter = DataObject::get_one('FatFooter');
            return $fatFooter;
        }
	
}

FatFooter.php

class FatFooter extends DataObject {
    static $db = array(
        'CurrentHappenings' => 'Text',
        'ToDoList' => 'Text',
        'Colophon' => 'Text'
    );
    static $has_one = array(
        'Page' => 'Page'
    );
    public function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Content.Fat Footer', new TextareaField('CurrentHappenings'));
        $fields->addFieldToTab('Root.Content.Fat Footer', new HTMLEditorField('ToDoList'));
        $fields->addFieldToTab('Root.Content.Fat Footer', new TextareaField('Colophon'));
        return $fields;
    }
}

Page.ss

            <% control GetFatFooter %>
                <ul id="fat-footer">
                    <li>
                        <h5>Current Happenings</h5>
                        <p>$CurrentHappenings</p>
                    </li>
                    <li>
                        <h5>To-Do List</h5>
                        <ul>
                            $ToDoList
                        </ul>
                    </li>
                    <li>
                        <h5>Colophon</h5>
                        <p>$Colophon</p>
                    </li>
                </ul>
            <% end_control %>

Avatar
yurigoul

Community Member, 203 Posts

24 December 2009 at 9:35am

I got this to work with sitetree and not with dataobject. Do not understand why it does not work with dataobject, but I have not tried it myself.

class FooterOfPage extends SiteTree {
   static $db = array(
	   'Col1' => 'HTMLText',
	   'Col2' => 'HTMLText'
	);
	static $icon = "themes/annomedia/images/icons/footer";
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Content.Column1', new HtmlEditorField('Col1', 'Footer column 1'));
		$fields->addFieldToTab('Root.Content.Column2', new HtmlEditorField('Col2', 'Footer column 2'));
		$fields->removeFieldFromTab("Root.Content","Main");
		$fields->removeFieldFromTab("Root.Content","Metadata");
		$fields->removeFieldFromTab("Root","Behaviour");
	return $fields;
	 }

	// can not be deleted
	public function canDelete() {
			false;
		}

	// can have no children
	static $allowed_children = 'none';

	//Do not show in menus
	static $ShowInMenus = false;

	// Only one can be created
	public function canCreate($member = null){
			$rights = parent::canCreate($member);
				if($rights == false)
		return false;

			$dobj = DataObject::get('FooterOfPage');
			if(!$dobj)
		return true;

			return $dobj->Count() == 0;
	}
}
class FooterOfPage_Controller extends ContentController {
	public function init() {
		parent::init();

	}
}
?>

And then in my Page_Controller I have

	//showing footer info
	public function Footer(){
		$myFooter = DataObject::get_one('FooterOfPage');
		return $myFooter;
	}

And I use

<% control Footer %>
	$Col1
<% end_control %>

Avatar
jondbaker

Community Member, 19 Posts

24 December 2009 at 9:11pm

Thanks for the speedy response! I still can't seem to get the tab to show up in the CMS though...

FatFooter.php

<?php
class FatFooter extends SiteTree {
    static $db = array(
        'CurrentHappenings' => 'Text',
        'ToDoList' => 'Text',
        'Colophon' => 'Text'
    );
    public function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Content.Fat Footer', new TextareaField('CurrentHappenings', 'Current Happenings'));
        $fields->addFieldToTab('Root.Content.Fat Footer', new HTMLEditorField('ToDoList', 'To-Do List'));
        $fields->addFieldToTab('Root.Content.Fat Footer', new TextareaField('Colophon'));
        return $fields;
    }
    //cannot be deleted
    public function canDelete() {
        false;
    }
    //can have no children
    static $allowed_children = 'none';
    //do not show in menus
    static $ShowInMenus = false;
    //only one can be created
    public function canCreate($member = null) {
        $rights = parent::canCreate($member);
        if($rights == false)
            return false;
        $dobj = DataObject::get('FatFooter');
        if(!$dobj)
            return true;
        return $dobj->Count() == 0;
    }
}
class FatFooter_Controller extends ContentController {
    public function init() {
        parent::init();
    }
}
?>

Page.php

class Page_Controller extends ContentController {
    ....
        public function FatFooter(){
            $fatFooter = DataObject::get_one('FatFooter');
            return $fatFooter;
        }
	
}

Page.ss

            <% control FatFooter %>
                <ul id="fat-footer">
                    <li>
                        <h5>Current Happenings</h5>
                        <p>$CurrentHappenings</p>
                    </li>
                    <li>
                        <h5>To-Do List</h5>
                        <ul>
                            $ToDoList
                        </ul>
                    </li>
                    <li>
                        <h5>Colophon</h5>
                        <p>$Colophon</p>
                    </li>
                </ul>
            <% end_control %>

Avatar
yurigoul

Community Member, 203 Posts

24 December 2009 at 11:53pm

Edited: 25/12/2009 3:18am

I copied your code and tried it in both 2.3.3 and 2.3.4 and in both instances using 3x addFieldToTab('Root.Content.Fat Footer', newfieldshizzle); gave me 3 tabs called Fat Footer.

I changed the code to addFieldToTab('Root.Content.FatFooter', newfieldshizzle); and everything worked ok after that.

EDIT: if this works, maybe your previous code will work as well? Let me know :-)
EDIT: and you did do a dev/build I assume (just being on the save side)

Avatar
jondbaker

Community Member, 19 Posts

25 December 2009 at 4:53am

Hmm, I went ahead and did a fresh installation of SS (I've been tinkering with things quite a bit and figured it wouldn't hurt) and corrected the 'Fat Footer' issue, but still no tab is being displayed...

I'm stumped since you were able to get the tabs to show up.

Go to Top