Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alcalyn/twig-extension-onpath

Twig extension which provide a filter to display a string depending on current route (usefull for active menu hover).
https://github.com/alcalyn/twig-extension-onpath

Last synced: 4 days ago
JSON representation

Twig extension which provide a filter to display a string depending on current route (usefull for active menu hover).

Awesome Lists containing this project

README

        

# 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

Through composer:

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

## 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 < 2.4**, don't use this declaration, but the next one.

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

For **Symfony < 2.4**:

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

## Using

You can do in your Twig template:

``` twig
{{ '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:

``` twig

```