2017 © Pedro Peláez
 

library silex-active-link

A Silex service provider for finding an active link in Twig.

image

herrera-io/silex-active-link

A Silex service provider for finding an active link in Twig.

  • Wednesday, August 14, 2013
  • by kherge
  • Repository
  • 0 Watchers
  • 0 Stars
  • 433 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Active Link

Build Status, (*1)

A very simple Silex service provider for checking active links in Twig., (*2)

Example

In PHP:, (*3)

use Herrera\Silex\ActiveLinkServiceProvider;
use Silex\Application;
use Silex\Provider\TwigServiceProvider;
use Symfony\Component\HttpFoundation\Request;

$app = new Application();

$app->get(
    '/',
    function (Application $app) {
        return $app['twig']->render('test.html.twig');
    }
)->bind('home');

$app->get(
    '/page',
    function (Application $app) {
        return $app['twig']->render('test.html.twig');
    }
)->bind('page');

$app->register(
    new TwigServiceProvider(),
    array(
        'twig.path' => '/path/to/templates'
    )
);

$app->register(
    new ActiveLinkServiceProvider()
);

$app->run(
    Request::create('/page')
);

The Twig template:, (*4)

<ul>
  <li{{ active("home") }}><a href="{{ path("home") }}">Home</a></li>
  <li{{ active("page") }}><a href="{{ path("page") }}">Page</a></li>
</ul>

The result when request page:, (*5)

<ul>
  <li><a href="/">Home</a></li>
  <li class="active"><a href="/page">Page</a></li>
</ul>

Installation

Use Composer:, (*6)

$ composer require "herrera-io/silex-active-link=~1.0"

Configuration

There is only one configuration parameter: active_link.snippet, (*7)

The active_link.snippet is the result returned if a link is active. By default, the result is class="active" (note that the space is included). Hopefully, this provides you with a far greater degree of flexibility in how you can use the new active Twig function., (*8)

The Versions

14/08 2013

dev-master

9999999-dev http://github.com/herrera-io/php-silex-active-link

A Silex service provider for finding an active link in Twig.

  Sources   Download

MIT

The Requires

 

The Development Requires

twig silex

14/08 2013

1.0.0

1.0.0.0 http://github.com/herrera-io/php-silex-active-link

A Silex service provider for finding an active link in Twig.

  Sources   Download

MIT

The Requires

 

The Development Requires

twig silex