Hide directories that have no content

This commit is contained in:
Stéphane Goetz 2015-07-29 08:30:41 +02:00
parent 114a0f29b7
commit 386f323dd0
2 changed files with 25 additions and 0 deletions

View File

@ -108,6 +108,10 @@ class Template
'class' => ($current_url === $link) ? 'active' : ''
];
} elseif ($node instanceof Directory) {
if (!$node->hasContent()) {
continue;
}
$link = ($path === '') ? $url : $path . '/' . $url;
$folder = [

View File

@ -98,6 +98,27 @@ class Directory extends Entry
$this->first_page = $first_page;
}
/**
* Used when creating the navigation.
* Hides folders without showable content
*
* @return bool
*/
public function hasContent()
{
foreach ($this->getEntries() as $node) {
if ($node instanceof Content) {
return true;
} elseif ($node instanceof Directory) {
if ($node->hasContent()) {
return true;
}
}
}
return false;
}
private function compareEntries($a, $b)
{
$name_a = explode('_', $a->name);