delormejonathan / active-menu-bundle
A Symfony extension to get active class base on current bundle/controller/action
Installs: 10 606
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- symfony/framework-bundle: >=3.4
- twig/twig: >=2.10
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>