Hi all,
I am trying to create a Widget that displays the content of a random sub page, i.e. in the widget I choose a parent page from the site tree, the frontend would then display the content of a random child page of that parent.
I started as you can see below. The TreeDropdownField gets displayed, but when I try to select it I get the error message "Error Getting Data".
RandomContentWidget.php
<?php
class RandomContentWidget extends Widget {
static $has_one = array(
"RandomContent" => "Page"
);
static $title = "Random Content";
static $cmsTitle = "Random Content Widget";
static $description = "Adds content from a random sub page to the widget sidebar.";
// the random selection is still missing at this stage ...
function getCMSFields() {
return new FieldSet(
new TreeDropdownField("Page", "Choose a random parent page:", "SiteTree")
);
}
}
?>
RandomContentWidget.ss
<div id="RandomContentWidget">
<% control RandomContent %>
<h3>$Title</h3>
$Content
< end_control %>
</div>
I am not very experienced with creating Silverstripe widgets. I just wrote my very first one yesterday. If anyone knows why I get the "Error Getting Data" message I would be happy for a hint.
Cheers!
Anatol