I tried this in 3.1-rc1:
HomePage.php
private static $has_one = array(
'MainWidgetArea' => 'WidgetArea',
'SidebarWidgetArea' => 'WidgetArea'
);
public function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Widgets', new WidgetAreaEditor('MainWidgetArea'));
$fields->addFieldToTab('Root.Sidebar', new WidgetAreaEditor('SidebarWidgetArea'));
return $fields;
}
and a template HomePage.ss which reads like this:
<div class="content-container unit size3of4 lastUnit">
<div>
$MainWidgetArea
</div>
<div class="content">$Content</div>
<div>
$Form
$PageComments
</div>
<aside>
$SidebarWidgetArea
</aside>
</div>
Then, I added/removed widgets (wrote two sample widgets that return a string) in the admin-section and experienced strange behavior:
- Log in to ss/admin
- create page "HomePage"
- define Widget 'weather forecast' for Widet-Area
- publish
- display page: weather widget is shown
- define Widget "facebook messages" for "Sidebar"-Widget Area
- publish
- display page: both template blocks are shown, but only the weather-widget shows the output from the widget-Controller
- admin: delete widget from main widget area
- publish
- display page: only the facebook-message widget is shown, but now includes the text, which is returned by the Widget-Controller
- admin: exchange the facebook messages in the sidebar with the weather widget and put the facbook widget into the main widget-area
- publish
- display page:both template blocks are shown but this time only the facebook message widget displays the text returned by the widget-ontroler
- admin: remove the facebook message widget
- publish
- display: whe facebook widget ist gone, the thext for the weather widget is shown
From this experience, I concluded that either I misunderstood the widget/template-mechanism or the widget is broken.