Skip to content

Instantly share code, notes, and snippets.

@jimbojsb
Created July 1, 2011 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimbojsb/1057888 to your computer and use it in GitHub Desktop.
Save jimbojsb/1057888 to your computer and use it in GitHub Desktop.
Module-specific layouts in Zend Framework
<?php
class Genoa_Controller_Plugin_SwitchLayout extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$module = $request->getModuleName();
$layoutName = $module;
$layoutPath = APPLICATION_PATH . "/modules/$module/views/layouts";
Zend_Layout::startMvc();
$layout = Zend_Layout::getMvcInstance();
$layout->setLayout($layoutName);
$layout->setLayoutPath($layoutPath);
}
}
@jimbojsb
Copy link
Author

jimbojsb commented Jul 1, 2011

Sets the default layout based on what module is about to be dispatched. Assumes that you will have a layout named the same as your module, but easy to change that to just be "layout" or similar.

@iceberg
Copy link

iceberg commented Jul 1, 2011

Maybe try to add layoutPath and layoutName into configuration, it will be better - for example in that case 3 modules can share one layout.

@jimbojsb
Copy link
Author

jimbojsb commented Jul 1, 2011

Yeah definitely. In this case, I didn't want them to share a layout. I could do one big layout folder though in case they needed to share one but also have separate ones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment