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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Widgets /

Discuss SilverStripe Widgets.

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

Widgets on a Page


Go to End


2 Posts   2002 Views

Avatar
merrick_sd

Community Member, 99 Posts

5 February 2013 at 1:55am

Edited: 05/02/2013 1:58am

How can i tell if a Page has 'any' widgets?

If a page has a widget the page will need a sidebar.

page.php

 

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

Layout >Page.ss



<% if MyWidgets %>  
<!-- Widgets -->
$MyWidgets	
<!-- endWidgets -->
<% else %>
<!-- NO Widgets -->
$MyWidgets	

<% end_if %>

result
On pages without widgets, no widgets show up as expected ...however the "if MyWidgets" isn't actually working! as the comment <!-- Widgets --> Always get rendered.

maybe i need a fuction on Page.phpto do some kind of check.

i want to do something like
if widges show a menu <span class="span3"> ..etc

Avatar
merrick_sd

Community Member, 99 Posts

5 February 2013 at 2:42am

Edited: 05/02/2013 2:42am


Page_Controller ...
//check if this page has widgets assigned to it!
	public function WidgetCheck() {
	$widgetid = $this->MyWidgetsID;
	$widgetdata = Widget::get()->filter(array('ParentID' => $widgetid));
	
		return $widgetdata;
	
	}


this works