Componette

Componette

inteve

inteve / navigation v3.0.0

Navigation component for Nette and more

download-cloud-line composer require inteve/navigation

Inteve\Navigation

Build Status Downloads this Month Latest Stable Version License

Navigation component for Nette Framework.

Donate

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/

  • v3.0.0 Version 3.0.0

    • added LinkFactory
    • replaced Navigation::formatPageId() by Helpers::normalizePageId()
    • added NavigationPage for pages
    • MenuControl: added setSubLevel() for rendering of submenu
    • MenuControl: added templates for Bootstrap 2
  • v2.0.0 Version 2.0.0

    • added ILink & ILinkGenerator (BC break)
    • requires PHP 5.6 or newer
    • added support for Nette 3.x
  • v1.3.0 Version 1.3.0

    • added hasChildren()
  • 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.

price-tag-2-line

Badges

guide-fill

Dependencies

php (>=5.3.0)
Componette Componette felix@nette.org