Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » Widget on a new Page Type

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 2031 Views
  • Chajoe
    Avatar
    Community Member
    3 Posts

    Widget on a new Page Type Link to this post

    Ok, so I was able to create a new page type with this instructions posted by Willr:
    ----------------------------
    You can have widgets on any page type by adding a WidgetArea to it. Open the page type code and add

    static $has_one = array(
    "MyWidgets" => "WidgetArea"
    );

    then in the getCMSFields you will need to add the widget drag and drop system

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("MyWidgets"));
    return $fields;
    }

    Then last but not least you need to open up your template file and add the code to render the widget area. In this example you would need to put $MyWidgets in the template some where.

    Remember to db/build and then flush the page.
    ----------

    I created a new HomePage.php, flushed the database and it loaded on the CMS... and it has the widget tab!
    !
    it took me a while to figure this out...
    My problem now is that the pages I create with that page type print out the following:

    Error
    The website server has not been able to respond to your request.

    I've been tryint to put the "$MyWidgets" to call the function on the page.ss of my template, also creating a new "HomePage.ss" but no luck...
    Please Help

    thx

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Widget on a new Page Type Link to this post

    Okay, now seems like you have done everything good, but did you run a http://mysite.com/db/build?flush=1

    if not try with that.

  • gkinane
    Avatar
    Community Member
    22 Posts

    Re: Widget on a new Page Type Link to this post

    Hi , I've tried your method to add widget type but no success. The following is the code I've added to page.php.
       public static $db = array(
       );
       
    public static $has_one = array(
       );
       static $has_one = array(
    "MyWidgets" => "WidgetArea"
    );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("MyWidgets"));
    return $fields;
    }

    When I save the file to server I then cannot login or run db/build. I also added the field to page.ss just before the last /div.

    I am a complete newbie to PHP and SS so I probably have screwed up the code somewhere. Any help appreciated.

    GK

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