Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

kherge-archive/php-silex-active-link

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Active Link

Build Status

A very simple Silex service provider for checking active links in Twig.

Example

In PHP:

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:

<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:

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

Installation

Use Composer:

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

Configuration

There is only one configuration parameter: active_link.snippet

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages