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

Adding widgets to other pages (SS 2.3)


Go to End
Reply


2 Posts   1664 Views

Avatar
Bluefruit

Community Member, 6 Posts

14 March 2009 at 2:40am

Hi

I am having trouble getting the to add widgets in the general page type using SS 2.3.

Pretty sure I have done all thats is necessary, have run /db/build/?flush=1 but the widgets tab just is not showing in the CMS for pages other than blog. Any help with this would be much appreciated.

---------------------
Page.php code;
---------------------

<?php

class Page extends SiteTree {

public static $db = array(
);

public static $has_one = array(
);

}
static $has_one = array(
"Sidebar" => "WidgetArea",
);

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

class Page_Controller extends ContentController {

public function init() {
parent::init();

// Note: you should use <% require %> tags inside your templates instead of putting Requirements calls here. However
// these are included so that our older themes still work
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}

/**
* Site search form
*/
function SearchForm() {
$searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Your query...';
$fields = new FieldSet(
new TextField("Search", "", $searchText)
);
$actions = new FieldSet(
new FormAction('results', 'Search')
);

return new SearchForm($this, "SearchForm", $fields, $actions);
}

/**
* Process and render search results
*/
function results($data, $form){
$data = array(
'Results' => $form->getResults(),
'Query' => $form->getSearchQuery(),
'Title' => 'Search Results'
);

return $this->customise($data)->renderWith(array('Page_results', 'Page'));
}

}

?>

---------------------
SideBar.ss code;
---------------------
<div id="Sidebar" class="typography">
<div class="sidebarBox">
<h3>
In this section
</h3>

<ul id="Menu2">
<% control Menu(2) %>
<% if Children %>
<li class="$LinkingMode"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levela"><span><em>$MenuTitle.XML</em></span></a>
<% else %>
<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levela"><span><em>$MenuTitle.XML</em></span></a>
<% end_if %>

<% if LinkOrSection = section %>
<% if Children %>
<ul class="sub">
<li>
<ul class="roundWhite">
<% control Children %>
<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levelb"><span><em>$MenuTitle.XML</em></span></a></li>
<% end_control %>
</ul>
</li>
</ul>
<% end_if %>
<% end_if %>
</li>
<% end_control %>
</ul>
<div class="clear"></div>
</div>
<div class="sidebarBottom"></div>
$Sidebar
</div>

Avatar
Invader_Zim

Community Member, 141 Posts

19 March 2009 at 12:30am

Hi.

Hope I can help you.

Have you had any errors with your code? Because I think there are some typos:

 

class Page extends SiteTree {
   
   public static $db = array(
   );
   
   public static $has_one = array( );    <--- I think this line can be deleted 'cause you call $has_one later again
   
}   <---- delete this

static $has_one = array(
   "Sidebar" => "WidgetArea",  <--- and delete this comma here
); 

...

So I hope this was of any help...

Cheers,
Christian