mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
FEATURE: move breadcrumbs out to a customizable template
This commit is contained in:
parent
95f35cc0d2
commit
8fe767b5f2
@ -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))
|
||||
))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
5
templates/BreadcrumbsTemplate.ss
Normal file
5
templates/BreadcrumbsTemplate.ss
Normal file
@ -0,0 +1,5 @@
|
||||
<% if Pages %>
|
||||
<% control Pages %>
|
||||
<% if Last %>$Title.XML<% else %><a href="$Link">$MenuTitle.XML</a> »<% end_if %>
|
||||
<% end_control %>
|
||||
<% end_if %>
|
Loading…
Reference in New Issue
Block a user