Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » I wanna make a sidebar, but how?

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

Page: 1 2 3 4 5
Go to End
Author Topic: 12864 Views
  • Aram
    Avatar
    Community Member
    598 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    which versoin are you using, I am using 2.23.......not sure if this would work with 2.3, it should but I havn't got round to testing much on that version.

    here is my code:

    SidebarPage.php

    <?php

    class SidebarPage extends Page {

    static $db = array(
    'SidebarText' => 'Text'
    );

    static $has_one = array(
    'Image1' => 'Image',
    'Image2' => 'Image',
    'Image3' => 'Image',
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.Main', new TextAreaField('SidebarText'), 'Content');
    $fields->addFieldToTab("Root.Content.Images", new ImageField('Image1'),'Content');
    $fields->addFieldToTab("Root.Content.Images", new ImageField('Image2'),'Content');
    $fields->addFieldToTab("Root.Content.Images", new ImageField('Image3'),'Content');

    return $fields;
    }

    }

    class SidebarPage_Controller extends Page_Controller{

    }

    ?>


    Page.php:

    <?php

    class Page extends SiteTree {
       static $db = array(
       );

       
    }

    class Page_Controller extends ContentController {
       
       function GetSidebar() {
    return DataObject::get_one("SidebarPage");
    }
    }

    ?>

    Sidebar.ss

    <% control GetSidebar %>

    $SidebarText

    $Image1

    $Image2

    $Image3

    <% end_control %>


    Page.ss

    <% include Sidebar %>

  • martin_w
    Avatar
    Community Member
    28 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    I use 2.2.3, the newest.

    When I delete the SidebarPage.php, then works my admin. So I think the error must be in this file.

    Must the function not be in class SidebarPage_Controller extends Page_Controller{}?

    I think so, it works when I put the function in it. (but first after db flush)

  • martin_w
    Avatar
    Community Member
    28 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    now I got it really work..
    I was wrong with "Must the function not be in class SidebarPage_Controller extends Page_Controller{}? "

    I think I had problems with db flush, thats why it worked not earlier.

    very big thank you.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    great to hear you got it working, the GetSidebar() function must go into Page.php beacause you want it to be available on every page. If we put it into SidebarPage.php then it would only be available when we were on a SidebarPage, which in this case we would never be as we are not using that page on its own.

    Anyway we got there in the end and your very welcome

  • martin_w
    Avatar
    Community Member
    28 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    and your very welcome

    I think then I may ask one more question ;)

    is it possible that in the text fields is also html available?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    You sure can

    You just have to use the HtmlEditorField field type. To do that add this to your SidebarPage class:

    static $db = array(
    'FieldName' => 'HTMLText'
    )

    function getCMSFields($cms) {
          $fields = parent::getCMSFields($cms);

    $fields->addFieldToTab("Root.Content.Images", new HtmlEditorField( "FieldName", "HTML Editor"));

    return $fields;   
       }

    that will add a tinyMCE editor like the one for Content

    There is a list of all the form field types you can use here: http://doc.silverstripe.com/doku.php?id=form-field-types

  • martin_w
    Avatar
    Community Member
    28 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    thats super!

    works all, thank you.

  • dreamstudio
    Avatar
    Community Member
    48 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    I have followed this and everything seems to work until I load up the sidebar.php file, i then try to flush the DB and it comes up with a silverstripe website error and i cant flush or go into the admin area

    Remove that one file and it works.

    Im using silverstripe 2.3.0

    The page i get up is a standard web error page so i cant see where it has the problem and not sure what in sidebar.php would have the problem

    12864 Views
Page: 1 2 3 4 5
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.