Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Widgets

Discuss SilverStripe Widgets.

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

Second widget with Control loop fails


Reply

2 Posts   723 Views

Avatar
jebbench

17 July 2011 at 2:24am (Last edited: 17 July 2011 2:25am), Community Member, 7 Posts

Good afternoon,

I've created two widgets, one that lists all pages of "HealthPage" type and provides a jump box and a second that lists all pages of "NewsPage" type.

Both widgets work fine if they are the only widget on the page, as soon as I add the other widget the widget that renders second will fail.

HealthPage Widget

class HealthDropDownWidget extends Widget {

public static $cmsTitle = 'Health Drop Down';
public static $description = 'A clickable drop down menu for quick navigation to health pages.';

public function HealthPageList() {
return DataObject::get("HealthPage", "Status = 'Published'", "Title");
}

}

HealthPage Template (trimmed)

<select onchange="javascript:window.location.assign(this.value);">
<option selected="selected" >Jump to section...</option>
<% control HealthPageList %>
<option value="$Link">$Title</option>
<% end_control %>
</select>

NewsPage Widget

class NewsWidget extends Widget {

public static $cmsTitle = 'News';
public static $description = 'Displays the latest news stories.';

public function NewsList() {
return DataObject::get("NewsPage", "Status = 'Published'", "Date");
}

}

NewsPage Template (trimmed)

<% control NewsList %>
<div>
<span>$date.Nice</span>
$Content
<a href="$Link">Read more...</a>
</div>
<% end_control %>

I've tried the same code on a fresh database and I had the same issues.

Any help is appreciated.

Cheers,
James Bench

Avatar
jebbench

18 July 2011 at 1:00am Community Member, 7 Posts

I've been having a play with this and I've discovered that it doesn't matter what's in the first widget the second widget will still fail, even if the first widget is just static HTML.

While trying to debug this I have discovered that my 'NewsList' or 'HealthPageList' functions don't get called if they're the second widget.

The widget still fail if they're the third or fourth widget.