Simple ZF2 Module that switches layouts based on arrays of layout names and route names

0.1.0 2013-05-29 17:58 UTC



This is a simple module to switch layout based on the currently matched route name


The module should be installed with composer. It's name is netglue/zf2-route-layout-module If you have problems installing with composer, check your minimum-stability setting.

Enable the module in your main config file. The module name you should enter is NetglueRouteLayout

Look in the vendor/netglue/zf2-route-layout-module directory once installed and look at the config files to see what can be altered for your app.


By default, the module does nothing as there are no configured routes or layouts.

To specify route/layout changes provide config in the following way:


'netglue_route_layout' => array(
	'by_route' => array(
		'my/route-name' => 'a-different-layout',
	'by_layout' => array(
		'a-different-layout' => array(



There is one service available from the service manager which is an instance of NetglueRouteLayout\Service\RouteLayout take a look in the /src dir... it's very simple.

// Add a route manually
$instance = $serviceLocator->get('NetglueRouteLayout\Service\RouteLayout');
$instance->addRoute('my/route-name', 'a-different-layout');
// Or
$instance->addRoutesByLayout('new-layout', array(
// Find out which layout a particular route has. Returns null if no specific layout has been configured
$layout = $instance->getLayout('my/route-name');