creating a //special// menu

Imagine you want to make something like a “commonly requested pages” menu on your site, but these pages are all over your site. The solution below shows you an elegant way to do this that also allows the website admin to change this menu.

Add the following to /mysite/code/Page.php

 
class Page extends SiteTree {
 static $db = array(
  "ShowInTabMenu" => "Boolean"
 );
 
 function getCMSFields() {
  $fields = parent::getCMSFields();
  $fields->addFieldToTab("Root.Behaviour", new CheckboxField("ShowInTabMenu", "Show special menu "));
  return $fields;
 }  
 
}
 
class Page_Controller extends ContentController {
 function init() {
  parent::init();
 }
 
 function topTabbers() {
  $whereStatement = "ShowInTabMenu = 1 AND ShowInMenus = 1";
  return DataObject::get("Page", $whereStatement); 
 }
}

and add the following to your /mysite/templates/Page.ss file

<% control topTabbers %>
   <li class="$FirstLast $LinkingMode"><a href="$Link" title="Go to the $Title.XML page"><span>$MenuTitle.XML</span></a></li>
<% end_control %>
 
recipes/page_selection_for_special_menu.txt · Last modified: 2010/05/05 23:38 (external edit)

Please use comments for notes, tips and corrections about the described functionality.
Use the Silverstripe Forum to ask questions.

blog comments powered by Disqus
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Creative Commons LicenseSilverStripe Documentation by SilverStripe is licensed under a Creative Commons Attribution 3.0 New Zealand License.
Based on a work at doc.silverstripe.com
Recent changes RSS feed Driven by DokuWiki