2017 © Pedro Peláez
 

library twig-extension-onpath

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

image

alcalyn/twig-extension-onpath

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

  • Monday, March 9, 2015
  • by alcalyn
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,198 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 4 % Grown

The README.md

Twig OnPath extension

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

Requires:, (*2)

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

Installation

Through composer:, (*3)

``` json { "require": { "alcalyn/twig-extension-onpath": "dev-master" } }, (*4)



## 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:, (*5)

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



## 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., (*7)

Note: You can enter more routes names., (*8)

So you can do for example in a menu navbar:, (*9)

twig <nav> <ul> <li class="{{ 'active'|onpath('home') }}"> <a href="{{ path('home') }}">Home</a> </li> <li class="{{ 'active'|onpath('blog', 'blog_post', 'blog_comment') }}"> <a href="{{ path('blog') }}">Blog</a> </li> <li class="{{ 'active'|onpath('about') }}"> <a href="{{ path('about') }}">About</a> </li> </ul> </nav>, (*10)

The Versions

09/03 2015

dev-master

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

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

  Sources   Download

MIT

The Requires

 

twig extension route symfony

09/03 2015

v1.0

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

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

  Sources   Download

MIT

The Requires

 

twig extension route symfony

07/03 2015

dev-dev

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

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

  Sources   Download

MIT

The Requires

 

twig extension route symfony