Jump to:

23455 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Selecting side bar blocks per page.

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 959 Views
  • keschrich
    Avatar
    Community Member
    2 Posts

    Selecting side bar blocks per page. Link to this post

    I have a sidebar on my website which contains a set of blocks. These blocks are basically just a single link (i.e. "Download White Papers" or "Request a Demo"). Some pages need to have some of the blocks visible, other pages have different blocks. After reading http://doc.silverstripe.org/doku.php?id=tutorial:5-dataobject-relationship-management and http://www.ssbits.com/create-a-static-sidebar/ it seemed as though it would be fairly simple to create a new page type called SideBarItem, and add a has_many to the Page class.

    I'm having a couple of problems though. First off, if I click "add" in the complex table field, I get an error stating that the function SideBarItem() is not defined. I can still however create pages of type SideBarItem in the site tree and get them to show up in the table though. Unfortunately when I do this, the check box to associate it with the page is disabled and cannot be clicked.

    Any thoughts would be appreciated (I am a newbie- sorry..)

    My code:

    Page.php

    class Page extends SiteTree {
    //--snip--
    public static $has_many = array( 'SidebarItems' => 'SidebarItem' );

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

    $tablefield = new HasManyComplexTableField(
    $this,
    'SidebarItems',
    'SidebarItem',
    array(
    'Title' => 'Title',
    ),
    'getCMSFields_forPopup'
    );

    $tablefield->setAddTitle('A SidebarItem');
    $fields->addFieldToTab('Root.Content.SidebarItems', $tablefield);

    return $fields;
    }
    //--snip

    SidebarItem.php:

    <?php

    class SidebarItem extends Page {
    }

    class SidebarItem_Controller extends Page_Controller {
    }

    ?>

    Obviously nothing special for SidebarItem..

    Thanks,
    Ken

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