PHPackages                             webfactory/navigation-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. webfactory/navigation-bundle

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

webfactory/navigation-bundle
============================

5.10.0(5mo ago)326.2k↑18.2%[1 PRs](https://github.com/webfactory/WebfactoryNavigationBundle/pulls)PHPPHP &gt;= 8.1CI passing

Since Dec 20Pushed 5mo ago6 watchersCompare

[ Source](https://github.com/webfactory/WebfactoryNavigationBundle)[ Packagist](https://packagist.org/packages/webfactory/navigation-bundle)[ RSS](/packages/webfactory-navigation-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (107)Used By (0)

WebfactoryNavigationBundle
==========================

[](#webfactorynavigationbundle)

Symfony Bundle featuring:

- A factory for creating the navigation tree, using BuildDirectors which you can add to, if needed
- Twig functions for rendering navigation elements (tree, ancestry, breadcrumbs) and inspecting the navigation tree

Installation
------------

[](#installation)

```
composer require webfactory/navigation-bundle

```

... and activate the bundle in your kernel, depending on your Symfony version.

Rendering navigation elements in Twig
-------------------------------------

[](#rendering-navigation-elements-in-twig)

### Simple Navigation List

[](#simple-navigation-list)

#### Syntax

[](#syntax)

```
{{ navigation_tree(root, maxLevels = 1, expandedLevel = 1, template = '@WebfactoryNavigation/Navigation/navigation.html.twig') }}

```

#### Examples

[](#examples)

```
{{ navigation_tree(root = {"webfactory_pages.page_id": root_page_id}) }}

{{ navigation_tree(
  root = {"webfactory_pages.page_id": root_page_id, "_locale": app.request.locale},
  template = 'AppBundle:Navigation:navigation.html.twig'
) }}

```

### Ancestry List

[](#ancestry-list)

An ancestry list is the active path from the given start level to the currently active node. Useful if you want to render e.g. the third level navigation outside of the regular navigation.

#### Syntax

[](#syntax-1)

```
{{ navigation_ancestry(startLevel, maxLevels = 1, expandedLevels = 1, template = '@WebfactoryNavigation/Navigation/navigation.html.twig') }}

```

#### Examples

[](#examples-1)

```
{{ navigation_ancestry(startLevel = 1) }}

{{ navigation_ancestry(startLevel = 1, template = '@App/Navigation/secondaryNav.html.twig') }}

```

### Breadcrumbs

[](#breadcrumbs)

#### Syntax

[](#syntax-2)

```
{{ navigation_breadcrumbs(template = '@WebfactoryNavigation/Navigation/breadcrumbs.html.twig') }}

```

#### Examples

[](#examples-2)

```
{{ navigation_breadcrumbs() }}
{{ navigation_breadcrumbs(template = '@App/Navigation/breadcrumbs.html.twig') }}

```

### Customisation

[](#customisation)

For each function mentioned above you can provide a Twig template in which you can extend the base template and overwrite each block. Please find the default blocks in `src/Resources/views/Navigation/navigationBlocks.html.twig`.

Example:

```
{# layout.html.twig: #}

...
{{ navigation_tree(root = {"webfactory_pages.page_id": root_page_id}, template = 'AppBundle:Navigation:navigation.html.twig') }}
...
```

```
{# AppBundle:Navigation:navigation.html.twig: #}

{% extends "@WebfactoryNavigation/Navigation/navigation.html.twig" %}

{% block navigation_list %}

        {{ parent() }}

{% endblock %}
```

Modifying the NavigationTree
----------------------------

[](#modifying-the-navigationtree)

Implement a `Webfactory\Bundle\NavigationBundle\Build\BuildDirector`. Example:

```
