Since I hate having any logic in the templates (and partial), here is my slightly improved version.
//module/templates/_breadcrumbElement.php <?php foreach ($node as $child): ?> <li> <a href="<?php echo $child->getPath($parent) ?>"><?php echo $child->getName() ?></a> <?php if (count($child->get('__children')) > 0): ?> <ul> <?php include_partial('node', array('node' => $child->get('__children'), 'parent' => $child)) ?> </ul> <?php endif; ?> </li> <?php endforeach; ?>
So, all the logic for constructing the URL is now in the Page :: getPath () method.
class Page extends BasePage { protected $path = false; public function __toString() { return $this->getSlug(); } public function getPath($parent = null) { if (!$this->path) { $this->path = join('/', null !== $parent ? array($parent->getPath(), $this) : array($this)); } return $this->path; } }
What I don't like when I need to pass $ parent to the :: getPath () page. It just does not make semantic meaning.
source share