Statistics
252
0
0
287d
Badges
Tags
menu
Dependencies

Inteve\Navigation

Navigation component for Nette Framework.

Become a Patron! Buy me a coffee

Installation

Download a latest package or use Composer:

composer require inteve/navigation

Inteve\Navigation requires PHP 5.3.0 or later and Nette 2.2+.

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\Form
{
	/** @var Navigation @inject */
	public $navigation;


	protected function createComponentNewsMenu()
	{
		// render items 'News 2016' & 'News 2015'
		$menu = new MenuControl($this->navigation);
		$menu->setSubTree('news');
		return $menu;
	}
}

Render breadcrumbs

<?php

use Inteve\Navigation\Navigation;
use Inteve\Navigation\BreadcrumbsControl;

class Presenter extends Nette\Application\UI\Form
{
	/** @var Navigation @inject */
	public $navigation;


	protected function createComponentBreadcrumbs()
	{
		return new BreadcrumbsControl($this->navigation);
	}
}

License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/

  • v1.2.0 Version 1.2.0

    • MenuControl - added key active to items
    • MenuControl - added setIgnoredPages()
  • v1.1.1 Version 1.1.1

    • MenuControl - fixed rendering of root
  • v1.1.0 Version 1.1.0

    • added support for static URLs
    • MenuControl: setParentPage() is deprecated, use setSubTree()
    • Readme: updated
  • v1.0.1 Version 1.0.1

    • bug fix - fixed addItemAfter() & addItemBefore()
  • v1.0.0 Version 1.0.0

    First public release.

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com