Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » Blog Widget duplicated in Sidebar - Please Help!

Discuss SilverStripe Widgets.

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

Page: 1 2
Go to End
Author Topic: 2514 Views
  • greenpea
    Avatar
    Community Member
    19 Posts

    Re: Blog Widget duplicated in Sidebar - Please Help! Link to this post

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

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Blog Widget duplicated in Sidebar - Please Help! Link to this post

    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.

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Blog Widget duplicated in Sidebar - Please Help! Link to this post

    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

  • greenpea
    Avatar
    Community Member
    19 Posts

    Re: Blog Widget duplicated in Sidebar - Please Help! Link to this post

    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.

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Blog Widget duplicated in Sidebar - Please Help! Link to this post

    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.

  • greenpea
    Avatar
    Community Member
    19 Posts

    Re: Blog Widget duplicated in Sidebar - Please Help! Link to this post

    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)

    2514 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.