Skip to content

Commit

Permalink
getgrav#10 add option to ignore current page
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Threadgold committed Oct 24, 2017
1 parent 1fd1ead commit 0b7a48a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions breadcrumbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ enabled: true
show_all: true
built_in_css: true
include_home: true
include_current: true
icon_home: ''
icon_divider_classes: 'fa fa-angle-right'
link_trailing: false
20 changes: 14 additions & 6 deletions classes/breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,33 @@ protected function build()
$grav = Grav::instance();
$current = $grav['page'];

while ($current && !$current->root()) {
$hierarchy[$current->url()] = $current;
$current = $current->parent();
}

// Page cannot be routed.
if (!$current) {
$this->breadcrumbs = array();
return;
}

if (!$current->root()) {

if ($this->config['include_current']) {
$hierarchy[$current->url()] = $current;
}

$current = $current->parent();

while ($current && !$current->root()) {
$hierarchy[$current->url()] = $current;
$current = $current->parent();
}
}

if ($this->config['include_home']) {
$home = $grav['pages']->dispatch('/');
if ($home && !array_key_exists($home->url(), $hierarchy)) {
$hierarchy[] = $home;
}
}


$this->breadcrumbs = array_reverse($hierarchy);
}
}

0 comments on commit 0b7a48a

Please sign in to comment.