PHPackages                             alcalyn/twig-extension-onpath - 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. [Templating &amp; Views](/categories/templating)
4. /
5. alcalyn/twig-extension-onpath

ActiveLibrary[Templating &amp; Views](/categories/templating)

alcalyn/twig-extension-onpath
=============================

Twig extension for Symfony 2, display a string depending on current route (usefull for active menu hover).

v1.0(11y ago)01.7kMITPHPPHP &gt;=5.3.2

Since Mar 7Pushed 11y agoCompare

[ Source](https://github.com/alcalyn/twig-extension-onpath)[ Packagist](https://packagist.org/packages/alcalyn/twig-extension-onpath)[ Docs](https://github.com/alcalyn/twig-extension-onpath)[ RSS](/packages/alcalyn-twig-extension-onpath/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

Twig OnPath extension
=====================

[](#twig-onpath-extension)

Twig extension for Symfony 2, display a string depending on current route (usefull for active menu hover).

Requires:

```
- php >= 5.3.2
- Twig >= 1.0
- Symfony2 >= 2.1

```

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

[](#installation)

Through composer:

```
{
    "require": {
        "alcalyn/twig-extension-onpath": "dev-master"
    }
}
```

Configuration
-------------

[](#configuration)

For Silex, see [OnPath integration guide for Silex](doc/integration_silex.md).

For Symfony2, see below:

Just register it as a service.

> **Warning**: If you are using **Symfony &lt; 2.4**, don't use this declaration, but the next one.

```
    twig.extension.onpath:
        class: Alcalyn\Extension\Twig\OnPath
        calls:
            - [ setRequestStack, [ @request_stack ] ]
        tags:
            - { name: twig.extension }
```

For **Symfony &lt; 2.4**:

```
    twig.extension.onpath:
        class: Alcalyn\Extension\Twig\OnPath
        scope: request
        calls:
            - [ setRequest, [ @request ] ]
        tags:
            - { name: twig.extension }
```

Using
-----

[](#using)

You can do in your Twig template:

```
{{ 'Hello'|onpath('home', 'user-index') }}
```

That displays 'Hello' only if you are on one of these routes: `home`, `user-index`.

> **Note**: You can enter more routes names.

So you can do for example in a menu navbar:

```

            Home

            Blog

            About

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

4081d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/17f0c4d65197a7aed6ecc8fdedd5a097c7238c9be19aca08c92c05d38fd8c29e?d=identicon)[alcalyn](/maintainers/alcalyn)

---

Top Contributors

[![alcalyn](https://avatars.githubusercontent.com/u/1588144?v=4)](https://github.com/alcalyn "alcalyn (4 commits)")

---

Tags

symfonytwigextensionroute

### Embed Badge

![Health badge](/badges/alcalyn-twig-extension-onpath/health.svg)

```
[![Health](https://phpackages.com/badges/alcalyn-twig-extension-onpath/health.svg)](https://phpackages.com/packages/alcalyn-twig-extension-onpath)
```

###  Alternatives

[tales-from-a-dev/twig-tailwind-extra

A Twig extension for Tailwind

34802.1k9](/packages/tales-from-a-dev-twig-tailwind-extra)[nucleos/antispam-bundle

This bundle provides some basic features to reduce spam in symfony forms.

52105.1k](/packages/nucleos-antispam-bundle)

PHPackages © 2026

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