Jump to:

22977 Posts in 11720 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » BreadCrumbs for new page types

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

Page: 1
Go to End
Author Topic: 1151 Views
  • andy_steel
    Avatar
    Community Member
    31 Posts

    BreadCrumbs for new page types Link to this post

    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();
       }
    }

    ?>

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: BreadCrumbs for new page types Link to this post

    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();

  • andy_steel
    Avatar
    Community Member
    31 Posts

    Re: BreadCrumbs for new page types Link to this post

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

    1151 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.