Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » Adding widgets programatically

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 1330 Views
  • Mo
    Avatar
    Community Member
    508 Posts

    Adding widgets programatically Link to this post

    Hi All,

    I was just wondering if there was a way of adding widgets to the widget area via code?

    Can I add something in my _config.php file? Or extend the relevent class?

    I am mainly looking at the blog module for doing this, and I cant hack the module, because it is pulled in via SVN externals.

    Any thoughts?

    Mo

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Adding widgets programatically Link to this post

    The only way to add them programmatically is to set the ParentID to the ID of the widget the that of the widget area. Something like..

    $widget = new Widget();
    $widget->ParentID = $widgetarea->ID;
    $widget->write();

    Rather then put that in your _config you could probably put that in your requireDefaultRecords() function on page so rebuilding the database triggers the check. You would populate $widgetarea by doing a query on the blogholder.

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