Original code Jan Marek.
Package requires PHP 7.0 or higher
The best way to install XRuff/Navigation is using Composer:
$ composer require xruff/navigation
or add package to composer.json file
{
"require": {
"xruff/navigation": "dev-master"
}
}
Register configuration in config.neon.
Config has two optional parameters - breadcrumbsTemplate
and menuTemplate
.
extensions:
navigation: XRuff\Components\Navigation\DI\NavigationExtension
# and optional settings for custom templates
navigation:
breadcrumbsTemplate: %appDir%/components/breadcrumbs.latte
Base presenter:
use Nette;
use XRuff\Components\Navigation\Navigation;
abstract class BasePresenter extends Nette\Application\UI\Presenter
{
/** @var Navigation @inject */
public $navigationFactory;
protected function createComponentNavigation($name) {
$nav = $this->navigationFactory->create($this);
$nav->setupHomepage('Homepage', $this->link('Homepage:'));
return $nav;
}
}
Another presenter extended from our BasePresenter:
use XRuff\Components\Navigation\Navigation;
class SomePresenter extends BasePresenter
{
/** @var XRuff\Components\Navigation\Navigation $nav */
private $nav;
protected function startup()
{
parent::startup();
$this->nav = $this['navigation']->add('Company name', $this->link('Company:'));
}
public function renderDefault()
{
$this->nav = $this->nav->add('Overview', false);
$this->nav->setCurrent(true);
}
public function renderDepartment()
{
$this->nav = $this->nav->add('Department name', false);
$this->nav->setCurrent(true);
}
public function renderOther()
{
$sec = $this->nav->add('Section', $this->link('Category:', ['id' => 1]));
$article = $sec->add('Article', $this->link('Article:', ['id' => 1]));
$this->nav->setCurrentNode($article);
// or $article->setCurrent(TRUE);
}
}
template.latte (breadcrumbs template is compatible with Bootstrap 3):
...
</head>
<body>
{control navigation:breadcrumbs}
...
Repository https://github.com/XRuff/Navigation.