Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Extendable breadcrumbs

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

Page: 1
Go to End
Author Topic: 1817 Views
  • barryvanveen
    Community Member
    11 Posts

    Extendable breadcrumbs Link to this post

    I've been busy with a couple of pages that use the DOM-module. Everything works great, I have a page with an overview, and a page with each individual data object.

    What I still miss is the opportunity to add my data-object-page to the breadcrumbs. Let's say I have a ResourcePage which shows all Resource objects. When you click on a Resource object, you go to it's individual page. At that point you are still using the ResourcePage code to retrieve the Resource object. Therefor the breadcrumbs show you are on the ResoursePage, not on the page of the Resource.

    At this moment there is no easy way to add an extra part to the breadcrumbs which would indicate that we visit an individual Resource. There's no Breadcrumb class that can be used to easily build custom breadcrumbs. Does anyone know how to accomplish this? Would this be something to build into Silverstripe at a point?


  • MarcusDalgren
    Community Member
    288 Posts

    Re: Extendable breadcrumbs Link to this post

    In short, you can always override the Breadcrumbs function in Sitetree. I always do and make it return a DataObjectSet instead of pre formatted html. It looks like this.

    public function Breadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = true) {
       $page = $this;
       $parts = array();
       $i = 0;
          && (!$maxDepth || sizeof($parts) < $maxDepth)
          && (!$stopAtPageType || $page->ClassName != $stopAtPageType)
       ) {
          if($showHidden || $page->ShowInMenus || ($page->ID == $this->ID)) {
             if($page->URLSegment == 'home') $hasHome = true;
             $parts[] = $page;
          $page = $page->Parent;
       if ($this->ClassName != "HomePage") {
          $parts[] = DataObject::get_one("HomePage");
       $parts = array_reverse($parts);
       $bdoSet = new DataObjectSet();
       foreach ($parts as $breadcrumb) {
       return $bdoSet;

    It's got some custom behaviour for my HomePage class that you probably want to strip out but you should be able to do what you want with that as your base.

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.