Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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).
- Host: GitHub
- URL: https://github.com/alcalyn/twig-extension-onpath
- Owner: alcalyn
- License: mit
- Created: 2015-01-29T15:41:12.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-09T16:21:40.000Z (over 9 years ago)
- Last Synced: 2024-10-11T13:12:29.011Z (28 days ago)
- Language: PHP
- Homepage:
- Size: 176 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```