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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

BreadCrumbs for new page types


Reply

3 Posts   1210 Views

Avatar
andy_steel

14 January 2009 at 5:08am Community Member, 31 Posts

I have created my own page types, NewsHolder and NewsItem. I have created pages so NewsItem is a child of NewsHolder.
But when I use $BreadCrumbs, the parent link in the breadcrumbs does not show.

What am I doing wrong? Do I need to override the getParent() function?

Here is my code:

<?php

class NewsHolder extends Page {
   static $db = array(
   );
   static $has_one = array(
   );
   static $allowed_children = array("NewsItem");
   static $default_child = "NewsItem";
   static $can_be_root = false;
}

class NewsHolder_Controller extends Page_Controller {
   function init() {
      parent::init();
   }
}

?>
<?php

class NewsItem extends Page {
   static $db = array(
      'Date' => 'Date'
   );
   static $has_one = array(
   );
   static $allowed_children = "none";
   static $default_parent = "news";
   static $can_be_root = false;
   static $icon = "mysite/images/treeicons/news";

   function getCMSFields() {
    $fields = parent::getCMSFields();
   
    $fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
       
    return $fields;
   }
}

class NewsItem_Controller extends Page_Controller {
   function init() {
      parent::init();
   }
}

?>

Avatar
dio5

17 January 2009 at 9:06am Community Member, 501 Posts

Just a question: I suppose 'newsholder' is a subpage as well? (as you've made can_be_root = false).

Normally breadcrumbs works out of the box.

You don't even need to put in the init() function everytime in the controller again, when all you do is calling parent::init();

Avatar
andy_steel

21 January 2009 at 4:12am (Last edited: 21 January 2009 4:12am), Community Member, 31 Posts

The problem was that "Show in menu?" option was not checked for the NewsHolder page.