delormejonathan/active-menu-bundle

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

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

This package is auto-updated.

Last update: 2024-11-10 15:48:49 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>