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.

Widgets /

Discuss SilverStripe Widgets.

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

Blog Widget duplicated in Sidebar - Please Help!


Go to End
Reply


14 Posts   2737 Views

Avatar
greenpea

Community Member, 19 Posts

21 June 2012 at 8:04pm

All the other page types that include $SideBar are saving widgets fine.

Avatar
MarijnKampf

Community Member, 164 Posts

21 June 2012 at 9:55pm

I remember encountering a similar problem, but I can't for the life of me remember what the solution was, I think it may have been in another forum post. I'll give it a ponder and see whether I can find the solution somewhere.

Avatar
socks

Community Member, 190 Posts

22 June 2012 at 9:35am

I had to remove Sidebar and add my own. Make sure all widgets are removed from the pages in the CMS before you do it, otherwise it can cause problems.

Page.php

class Page extends SiteTree {

public static $has_one = array(
   'SidebarWidgets' => 'WidgetArea'
);

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

   $fields->addFieldToTab('Root.Content.Widgets', new WidgetAreaEditor('SidebarWidgets'));
   
   return $fields;
}

}

BlogHolderDecorator.php

class BlogHolderDecorator extends DataObjectDecorator {
   
   public function getCMSFields() {
    $fields = parent::getCMSFields();
    $this->extend('updateCMSFields', $fields);
    return $fields;
   }
   
   public function updateCMSFields(FieldSet $fields) {
      $fields->removeByName('SideBar');
      
      return $fields;
   }

}

_config.php

DataObject::add_extension('BlogHolder', 'BlogHolderDecorator');

YourTemplate.ss
replace $Sidebar with $SidebarWidgets

Avatar
greenpea

Community Member, 19 Posts

24 June 2012 at 12:56am

Thanks everyone. I think the problem lay with my localhost, after numerous errors I dropped the MySQL database and now all is working fine (I used the code from the tutorial with no additions).

The widget list does display twice in the blog CMS admin area (attached), but widgets are not duplicated in the sidebar.

Avatar
MarijnKampf

Community Member, 164 Posts

24 June 2012 at 2:26am

Could you try the code from the post http://www.silverstripe.org/widgets-2/show/16100#post310887 again to see whether it works now? As this should remove the duplication from the CMS.

Avatar
greenpea

Community Member, 19 Posts

24 June 2012 at 6:59pm

I tried that code and saved widgets appear in the front end but are now viewable in the CMS (so I am unable to customise them)

Go to Top