PHPackages                             feskol/php-navigation - 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. feskol/php-navigation

ActiveLibrary

feskol/php-navigation
=====================

A simple and effective Navigation to manage active states in navigation structures.

v3.0.0(1y ago)07891MITPHPPHP ^8.1CI passing

Since Jan 13Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/feskol/php-navigation)[ Packagist](https://packagist.org/packages/feskol/php-navigation)[ RSS](/packages/feskol-php-navigation/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (1)

PHP-Navigation
==============

[](#php-navigation)

[![GitHub Release](https://camo.githubusercontent.com/e4c41ce73da38658eb869353eaaf32fe64f091361a38e5f3615e01b281d33b11/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6665736b6f6c2f7068702d6e617669676174696f6e)](https://github.com/feskol/php-navigation/releases)[![GitHub License](https://camo.githubusercontent.com/66f6bdc01427bb5b6df6494fe936931405962dd5fc94909b0c40792813866386/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6665736b6f6c2f7068702d6e617669676174696f6e)](https://camo.githubusercontent.com/66f6bdc01427bb5b6df6494fe936931405962dd5fc94909b0c40792813866386/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6665736b6f6c2f7068702d6e617669676174696f6e)[![Packagist Downloads](https://camo.githubusercontent.com/a793edd12a3bcf88a48432373dec618728f5bd028f9eccb4d371da4d62900fa3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6665736b6f6c2f7068702d6e617669676174696f6e)](https://packagist.org/packages/feskol/php-navigation)[![codecov](https://camo.githubusercontent.com/77b858143483d33edc863a713a48eae571d33cdac1aa712a72cc2b4327df1855/68747470733a2f2f636f6465636f762e696f2f67682f6665736b6f6c2f7068702d6e617669676174696f6e2f67726170682f62616467652e7376673f746f6b656e3d5a4a365a513841554759)](https://codecov.io/gh/feskol/php-navigation)

Overview
--------

[](#overview)

A simple and effective Navigation to manage active states in navigation structures.
For Symfony integration, check out the [NavigationBundle](https://github.com/feskol/NavigationBundle).

Features
--------

[](#features)

- Automatically tracks a link's active status and makes it easy to check if a parent navigation item has active child links.
- Easy to set up and integrate into existing projects.
- Flexible and extensible for complex navigation structures.

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

[](#installation)

Install via Composer:

```
composer require feskol/php-navigation
```

Usage
-----

[](#usage)

### Building Your Navigation Structure

[](#building-your-navigation-structure)

```
use Feskol\Navigation\Link;
use Feskol\Navigation\Navigation;

// create links
$navLink = new Link();
$navLink->setTitle('Company')
    ->setHref('/company');

$subNavLink = new Link();
$subNavLink->setTitle('About us')
    ->setHref('/company/about-us')
    ->setIsActive(true);

// add the $subNavLink as $navLinks Child
$navLink->addChild($subNavLink);

// To have all links in one place you can use the provided Navigation class:
$navigation = new Navigation();
$navigation->setTitle('MyNavigation');

// add the created $navLink to the Navigation
$navigation->addLink($navLink);
```

Iterating through Navigation links:

```
foreach ($navigation->getLinks() as $link){
    echo $link->getTitle(); // "Company"
    echo $link->hasActiveChildren(); // "true" - because the child is active

    foreach($link->getChildren() as $subLink){
        echo $link->getTitle(); // "About us"
        echo $link->isActive(); // "true"
    }
}
```

### Common link data

[](#common-link-data)

The `Link` class provides setter and getter methods for the common attributes of an ``-tag.
The most commonly used ones are `href=""` and `target=""`:

```
use Feskol\Navigation\Link;

$link = new Link();

// href
$link->setHref('/company/about-us');
$link->getHref(); // "/company/about-us"

// target
$link->setTarget(Link::TARGET_BLANK);
$link->getTarget(); // "_blank"
```

To view all available methods for the common link data, check out the [`AbsctractHyperLink` class](https://github.com/feskol/php-navigation/blob/main/src/AbstractHyperLink.php).

### Additional Data

[](#additional-data)

There are often situations where you need additional data for your navigation, such as icons or images.
The best approach is to create your own class (e.g. `MyCustomLink`) that extends the `Link` class:

```
use Feskol\Navigation\Link;

class MyCustomLink extends Link
{
    private ?string $icon = null;

    public function getIcon(): ?string {
        return $this->icon;
    }

    public function setIcon(?string $icon): static {
        $this->icon = $icon;
        return $this;
    }
}
```

Then use your `MyCustomLink` class instead of the `Link` class:

```
$link = new MyCustomLink();
$link->setTitle('Company')
    ->setHref('/company')
    ->setIcon('bi bi-user'); // For example, using Bootstrap-Icon classes
```

Handling translations in your frontend
--------------------------------------

[](#handling-translations-in-your-frontend)

### Symfony

[](#symfony)

In Symfony, you can use the `TranslatableMessage` class to hold translation infos which you can use in your frontend.
In Twig, apply the `|trans` filter to translate the `TranslatableMessage`.

Both the `Navigation` and `Link` classes accept any object implementing the `\Stringable` interface in their `setTitle()` methods. This allows you to pass objects like `TranslatableMessage` or custom classes with a `__toString()` method.

#### Example in Symfony

[](#example-in-symfony)

```
use Feskol\Navigation\Link;
use Feskol\Navigation\Navigation;
use Symfony\Component\Translation\TranslatableMessage;

$navigation = new Navigation();
$navigation->setTitle(new TranslatableMessage('MyNavigation', [], 'navigation'));

$navLink = new Link();
$navLink->setTitle(new TranslatableMessage(
    'Nav-Item for %customerName%',
    ['%customerName%' => $customer->getName()], // Dynamic translation parameters
    'navigation' // Translation domain
));

$navigation->addLink($navLink);
```

And then in your Twig template:

```
{# @var \Feskol\Navigation\Navigation navigation #}

Translated Navigation Title: {{ navigation.title|trans }}

{% for link in navigation.links %}
    Translated Link Title: {{ link.title|trans }}
{% endfor %}
```

Contribution Guidelines
-----------------------

[](#contribution-guidelines)

We welcome contributions to this project! To ensure clarity and fairness for all contributors, we require that all contributors sign our **Contributor License Agreement (CLA)**.

By signing the CLA, you confirm that:

1. You grant us the perpetual, worldwide, non-exclusive, royalty-free, irrevocable right to use, modify, sublicense, and distribute your contribution as part of this project or any other project.
2. You retain ownership of your contribution, but grant us the rights necessary to use it without restriction.
3. Your contribution does not violate the rights of any third party.

### How to Sign the CLA

[](#how-to-sign-the-cla)

Before submitting a pull request, please sign the CLA using the following link:
[Sign the CLA](https://cla-assistant.io/feskol/php-navigation)

Contributions cannot be merged unless the CLA is signed.

Thank you for your contributions and for helping us build something great!

Testing
-------

[](#testing)

We're using phpunit.

Run tests:

```
php vendor/bin/phpunit
```

❤️ Support This Project
-----------------------

[](#️-support-this-project)

If you find this project helpful and would like to support my work:

- 🌟 **Star the repository** to show your appreciation.
- 💸 **Donate via**:
    - Buy Me a Coffe: [![Buy Me A Coffee](https://camo.githubusercontent.com/ac0691838acdb314464d588b2096fbe16499f4152948d0631746ce0c86661863/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275792532304d6525323061253230436f666665652d6666646430303f266c6f676f3d6275792d6d652d612d636f66666565266c6f676f436f6c6f723d626c61636b)](https://buymeacoffee.com/feskol)
    - PayPal: [![PayPal](https://camo.githubusercontent.com/20eac948eeb9fbdfa3b1a692dd1eef93f04d1e523d4822acfa0f86e8742b1978/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50617950616c5f4d652d3030333038373f6c6f676f3d70617970616c266c6f676f436f6c6f723d666666)](https://paypal.me/feskol)

Thank you for your support!

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance69

Regular maintenance activity

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

5

Last Release

451d ago

Major Versions

v1.0.0 → v2.0.02025-02-13

v2.0.2 → v3.0.02025-02-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/290ad55e53c4be382518ca4d8c1f5b2a2897c6be6d444c62a0492954735ba8ea?d=identicon)[Festim](/maintainers/Festim)

---

Top Contributors

[![feskol](https://avatars.githubusercontent.com/u/67876946?v=4)](https://github.com/feskol "feskol (18 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")

---

Tags

navigationnavigation-active-statenavigation-helperphpphp-libraryphp8php83php84navigationnavigation-active-statenavigation-helper

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/feskol-php-navigation/health.svg)

```
[![Health](https://phpackages.com/badges/feskol-php-navigation/health.svg)](https://phpackages.com/packages/feskol-php-navigation)
```

###  Alternatives

[spatie/menu

Html menu generator

7592.9M6](/packages/spatie-menu)[verbb/navigation

Create navigation menus for your site.

90683.7k17](/packages/verbb-navigation)[kartik-v/yii2-widget-sidenav

An enhanced side navigation menu styled for bootstrap (sub repo split from yii2-widgets)

364.0M8](/packages/kartik-v-yii2-widget-sidenav)[pingpong/menus

Laravel Menus

70194.4k13](/packages/pingpong-menus)[kartik-v/yii2-widget-affix

A scrollspy and affixed enhanced navigation to highlight page sections (sub repo split from yii2-widgets)

153.8M3](/packages/kartik-v-yii2-widget-affix)[laminas/laminas-navigation

Manage trees of pointers to web pages in order to build navigation systems

162.5M63](/packages/laminas-laminas-navigation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
