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.

Customising the CMS /

Extendable breadcrumbs


Reply


2 Posts   1935 Views

Avatar
barryvanveen

Community Member, 11 Posts

23 July 2010 at 10:59pm

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?

Barry

Avatar
MarcusDalgren

Community Member, 288 Posts

25 July 2010 at 7:37am

Edited: 25/07/2010 7:41am

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;
   while(
      $page
      && (!$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) {
      $bdoSet->push($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.