FEATURE: move breadcrumbs out to a customizable template

This commit is contained in:
Will Rossiter 2012-02-11 15:13:27 +13:00
parent 95f35cc0d2
commit 8fe767b5f2
2 changed files with 16 additions and 17 deletions

View File

@ -154,13 +154,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
"Versioned('Stage', 'Live')",
);
/**
* Delimit breadcrumb-links generated by BreadCrumbs()
*
* @var string
*/
public static $breadcrumbs_delimiter = " » ";
/**
* Whether or not to write the homepage map for static publisher
*/
@ -625,24 +618,25 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
*/
public function Breadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false) {
$page = $this;
$parts = array();
$i = 0;
$pages = array();
while(
$page
&& (!$maxDepth || sizeof($parts) < $maxDepth)
&& (!$maxDepth || count($pages) < $maxDepth)
&& (!$stopAtPageType || $page->ClassName != $stopAtPageType)
) {
if($showHidden || $page->ShowInMenus || ($page->ID == $this->ID)) {
if(($page->ID == $this->ID) || $unlinked) {
$parts[] = Convert::raw2xml($page->Title);
} else {
$parts[] = ("<a href=\"" . $page->Link() . "\">" . Convert::raw2xml($page->Title) . "</a>");
}
$pages[] = $page;
}
$page = $page->Parent;
}
return implode(self::$breadcrumbs_delimiter, array_reverse($parts));
$template = new SSViewer('BreadcrumbsTemplate');
return $template->process($this->customise(new ArrayData(array(
'Pages' => new ArrayList(array_reverse($pages))
))));
}
/**

View File

@ -0,0 +1,5 @@
<% if Pages %>
<% control Pages %>
<% if Last %>$Title.XML<% else %><a href="$Link">$MenuTitle.XML</a> &raquo;<% end_if %>
<% end_control %>
<% end_if %>