inteve / navigation
Navigation component for Nette Framework.
Fund package maintenance!
Other
Installs: 6 603
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: 7.4 - 8.2
- latte/latte: ^2.4 || ^3.0
- nette/application: ^2.4 || ^3.0
- nette/utils: ^2.4 || ^3.0 || ^4.0
Requires (Dev)
- nette/http: ^2.4 || ^3.0
- nette/tester: ^2.0
README
Navigation component for Nette Framework.
Installation
Download a latest package or use Composer:
composer require inteve/navigation
Inteve\Navigation
requires PHP 7.4 or later and Nette 2.2+ or 3.0+.
Usage
Define pages
<?php use Inteve\Navigation\Navigation; $navigation = new Navigation; $navigation->addPage('/', 'Homepage'); $navigation->addPage('contact', 'Contact'); $navigation->addPage('news', 'News'); $navigation->addPage('news/2016', 'News 2016'); $navigation->addPage('news/2015', 'News 2015'); $navigation->setDefaultPage('/'); $navigation->setCurrentPage('news/2016'); $navigation->isPageCurrent('news/2016'); // returns bool $navigation->isPageActive('news'); // returns bool
Breadcrumbs
<?php $navigation->addItem('Detail'); $navigation->addItemBefore('/', 'My Website', ':Homepage:default'); $navigation->addItemAfter('news/2016', 'Page 1', ':News:default', array('page' => 1)); $breadcrumbs = $navigation->getBreadcrumbs();
Render menu
<?php use Inteve\Navigation\Navigation; use Inteve\Navigation\MenuControl; class NewsPresenter extends Nette\Application\UI\Presenter { /** @var Navigation @inject */ public $navigation; protected function createComponentNewsMenu() { // render items 'News 2016' & 'News 2015' $menu = new MenuControl($this->navigation); $menu->setSubTree('news'); return $menu; } protected function createComponentSubMenu() { // Renders submenu by current page // for setCurrentPage('news') or setCurrentPage('news/any/thing') it renders items 'news/2016' & 'news/2015' // for setCurrentPage('contact') it renders nothing $menu = new MenuControl($this->navigation); $menu->setSubTree('/'); $menu->setSubLevel(1); return $menu; } }
In Latte template:
{control newsMenu}
Render breadcrumbs
<?php use Inteve\Navigation\Navigation; use Inteve\Navigation\BreadcrumbsControl; class Presenter extends Nette\Application\UI\Presenter { /** @var Navigation @inject */ public $navigation; protected function createComponentBreadcrumbs() { return new BreadcrumbsControl($this->navigation); } }
In Latte template:
{control breadcrumbs}
License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/