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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Reversed breadcrumbs as Page Title


Go to End


2 Posts   2694 Views

Avatar
pinkdigital

Community Member, 7 Posts

23 November 2008 at 9:21pm

Hi
On some sites that we have built we reverse the breadcrumbs to make the page title... so if the breadcrumbs for a page where "Web Solutions » E-Commerce" in the page title we would have "E-Commerce | Web Solutions | Site Name etc"

Is there a way to do this in SilverStripe without too much hassle.

Avatar
Willr

Forum Moderator, 5523 Posts

24 November 2008 at 6:37pm

You can just go on the code from the Breadcrumbs() function (located in sapphire/core/model/SiteTree.php). Copy this code to your Page class in mysite/code/Page.php
and might be something like

public function ReservedBreadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false) {
		$page = $this;
		$parts = array();
		$i = 0;
		while(
			$page  
 			&& (!$maxDepth || sizeof($parts) < $maxDepth) 
 			&& (!$stopAtPageType || $page->ClassName != $stopAtPageType)
 		) {
			if($showHidden || $page->ShowInMenus || ($page->ID == $this->ID)) { 
				$parts[] = $page->Title; 
			}
			$page = $page->Parent;
		}

		return implode(' | ', $parts);
	}

Then just try $ReservedBreadcrumbs in the template