Jump to:

1383 Posts in 492 Topics by 521 members

Themes

SilverStripe Forums » Themes » Editing footer from within the back-end editor?

Discuss SilverStripe Themes.

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

Page: 1 2
Go to End
Author Topic: 3238 Views
  • donall
    Avatar
    Community Member
    7 Posts

    Editing footer from within the back-end editor? Link to this post

    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?

  • yurigoul
    Avatar
    Community Member
    202 Posts

    Re: Editing footer from within the back-end editor? Link to this post

    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";

  • donall
    Avatar
    Community Member
    7 Posts

    Re: Editing footer from within the back-end editor? Link to this post

    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!

  • jondbaker
    Avatar
    Community Member
    19 Posts

    Re: Editing footer from within the back-end editor? Link to this post

    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 %>

  • yurigoul
    Avatar
    Community Member
    202 Posts

    Re: Editing footer from within the back-end editor? Link to this post

    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 %>

  • jondbaker
    Avatar
    Community Member
    19 Posts

    Re: Editing footer from within the back-end editor? Link to this post

    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 %>

  • yurigoul
    Avatar
    Community Member
    202 Posts

    Re: Editing footer from within the back-end editor? Link to this post

    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)

  • jondbaker
    Avatar
    Community Member
    19 Posts

    Re: Editing footer from within the back-end editor? Link to this post

    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.

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