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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Widgets /

Discuss SilverStripe Widgets.

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

Blog Widget duplicated in Sidebar - Please Help!


Go to End


14 Posts   6899 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, 176 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, 191 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, 176 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