Evan Coury: Module-specific layouts in Zend Framework 2

Evan Coury has posted Module-specific layouts in Zend Framework 2

First, I should point out that the title of this post is a bit of an intentional misnomer. There’s really no such thing as “module-specific” anything in ZF2, so what we’re really talking about is the topmost namespace of the controller being dispatched. So in the case of MyModuleControllerSomeController, the topmost namespace would be MyModle. In most cases, this will be the name of a given module.

Here’s how you can easily switch the layout (or perform any other arbitrary logic) for a specific module in Zend Framework 2.0 (as of d0b1dbc92)

He shows how easy it is to register an event that is only triggered when an action belonging to the namespace of the current module is dispatched. If you need to change the layout for a given module, this is the best way to do it as of today.

His point that a Module is merely the namespace of the dispatch controller is very important to understand too!