Jump to:

520 Posts in 248 Topics by 263 members

Content Editor Discussions

SilverStripe Forums » Content Editor Discussions » Making content on all pages editing on CMS

Forum for content editors and CMS users.

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

Page: 1 2 3
Go to End
Author Topic: 4666 Views
  • kompideal
    Avatar
    Community Member
    7 Posts

    Making content on all pages editing on CMS Link to this post

    Hi
    I am searching solution for one problem I have.

    I have Silverstripe 2.3.1 version. I have website there I want to place various content on one page.
    For example:
    I have pages named "About us" and "Solution", these pages have main content area and sidebar area. I want that I could edit these pages on CMS: various content in main area; and the same content in sidebar area in all pages and sidebar area could be editing in CMS in one page and shown for public in all pages.

    I hope that I explained my problem well.
    So how can I do this? Thanks for help.

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Making content on all pages editing on CMS Link to this post

    Yup that is a common request and easy to implement, have a look at this tutorial which will step you through it http://www.ssbits.com/create-a-static-sidebar/

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: Making content on all pages editing on CMS Link to this post

    Yeah, I do it like this:

    1. I'll have a HomePage template, to which I add fields that I consider "global". (I will collect them under a "global" tab in the cms.)

    2. On Page.php, I include the following function:

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

    3. This means that I can call home from every Page template (or a template based on a page type that extends from page) to show things that I've set in the "global" section on my home page in the cms. (For instance $callHome.WhateverField.)

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Making content on all pages editing on CMS Link to this post

    SilverRay

    Could you explain a little further what you are doing here?

    I want to set my footer to be global. I want that a user can edit the footer info in an editer on a tab called "Footer" - like your "Global" tab.

    Please help me with the steps I need to take to make this work.

    Thank you,
    Steve

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: Making content on all pages editing on CMS Link to this post

    OK, well, I make use of the fact that your home page is always there and has a separate page type ("HomePage.php"). Example for HomePage.php:

    <?php

    class HomePage extends Page {
    ...
       public static $db = array(
          'SomeFooter' => 'Text'
       );

       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root', new TabSet('GlobalContent'));
          $fields->addFieldToTab( 'Root.GlobalContent.Footer', new TextField('SomeFooter', 'Put Footer text here.'));
          return $fields;
       }
    ...
    }

    class HomePage_Controller extends Page_Controller {
    }

    ?>

    This means I declare a variable 'SomeFooter' to put in your Footer's content, and I create a tab for the editor in which you can actually do that. Then in Page.php:

    class Page_Controller extends ContentController {
    ...
       public function callHome(){
          return DataObject::get_one('HomePage');
       }
    ...
    }

    ?>

    This means that in every page template of the type 'Page' (or a type extended thereof) I can call $callHome.SomeFooter to render the content of SomeFooter for that particular page. The function callHome calls the HomePage dataobject and -in this case- its SomeFooter attribute.

    HTH

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Making content on all pages editing on CMS Link to this post

    Thank you SilverRay!

    You opened up a whole new world for me!

    I will add to this post as I go along. The first thing I ran into was that I setup the $fields code after my other tab code - this removed all my tabs. So I pasted the $fields to the top, before the page tabs and they all came back.

    I have added the editor ...
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root', new TabSet('GlobalContent'));
    $fields->addFieldToTab( 'Root.GlobalContent.FooterContent', new HtmlEditorField('SomeFooter', 'Use the editer below to update your footer content'));

    To be continued...

    The backend all seems fine. The values are saving and all if fine.

    Onto the HomePage.ss file...

    Should that just be a duplicate of the Page.ss file? I'm getting this error...

    [Warning] file_get_contents() [function.file-get-contents]: Filename cannot be empty
    GET /

    Line 277 in /home/landingp/public_html/sapphire/core/SSViewer.php

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Making content on all pages editing on CMS Link to this post

    My Home Page (from HomePage.ss) is not showing up in the Behavior tab ??

    Where is this function being called - callHome ?

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

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Making content on all pages editing on CMS Link to this post

    I can't seem to get my Home Page to show up - any ideas based on the error I'm getting?

    4666 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.