I know that it is too late to answer this question, and also that there are many answers that already exist, but in case someone considers this question, it can be useful.
In the primary or any module Module.php write this -
class Module { public function onBootstrap(MvcEvent $e) { $sm = $e->getApplication()->getServiceManager(); $router = $sm->get('router'); $request = $sm->get('request'); $matchedRoute = $router->match($request); $params = $matchedRoute->getParams(); $controller = $params['controller']; $action = $params['action']; $module_array = explode('\\', $controller); $module = array_pop($module_array); $route = $matchedRoute->getMatchedRouteName(); $e->getViewModel()->setVariables( array( 'CURRENT_MODULE_NAME' => $module, 'CURRENT_CONTROLLER_NAME' => $controller, 'CURRENT_ACTION_NAME' => $action, 'CURRENT_ROUTE_NAME' => $route, ) ); } }
Then you can use the $CURRENT_MODULE_NAME variable in your layout file (as done in the question itself). The remaining variables mentioned in the code above can be used if required.
source share