delormejonathan/active-menu-bundle

A Symfony extension to get active class base on current bundle/controller/action

Installs: 13 171

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 1

Open Issues: 0

Type:symfony-bundle

pkg:composer/delormejonathan/active-menu-bundle

v1.0.17 2024-01-10 14:00 UTC

This package is auto-updated.

Last update: 2025-10-10 17:37:40 UTC


README

Installation

composer require delormejonathan/active-menu-bundle
public function registerBundles()
{
    $bundles = array(
        new DelormeJonathan\ActiveMenuBundle\DelormeJonathanActiveMenuBundle(),
    );

Usage in your twig template

For example, if you have this action AppBundle\Controller\ElementsController::list, you can

Get the current bundle name

{{ bundle_name() }} # returns App

Get the current controller name

{{ controller_name() }} # returns Elements

Get the current action name

{{ action_name() }} # returns list

Controller filter

It works with both full and short paths

<!-- classname is the string returned if controller matchs (you can replace it by 'active' or 'current') -->
<li class="{{ 'AppBundle\Controller\ElementsController' | is_controller_active('classname') }}"></li>
<li class="{{ 'Elements' | is_controller_active('classname') }}"></li>

Action filter

<!-- classname is the string returned if controller matchs (you can replace it by 'active' or 'current') -->
<li class="{{ 'list' | is_action_active('classname') }}"></li>

Combined controller/action filter

<!-- classname is the string returned if controller matchs (you can replace it by 'active' or 'current') -->
<li class="{{ [ 'Elements::list' ] | is_action_active('classname') }}"></li>
<li class="{{ [ 'AppBundle\Controller\Elements::list' ] | is_action_active('classname') }}"></li>