I'd like to name my default layout file something other than layout.phtml, since it doesn't really describe what type of layout it is. How can I do this? Thanks!
From your Bootstrap.php file, you could do something like this:
protected function _initLayoutName()
{
// use sitelayout.phtml as the main layout file
Zend_Layout::getMvcInstance()->setLayout('sitelayout');
}
If you want to use a different layout for a different module, you need to register a plugin in the Bootstrap and have the plugin contain the following code:
class Application_Plugin_LayoutSwitcher extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$module = $request->getModuleName(); // get the name of the current module
if ('admin' == $module) {
// set the layout to admin.phtml if we are in admin module
Zend_Layout::getMvcInstance()->setLayout('admin');
} else if ('somethingelse' == $module) {
Zend_Layout::getMvcInstance()->setLayout('somethingelse');
}
}
}
From within your application.ini, you can do this to set the layout script:
resources.layout.layout = "layoutname"
This will not work on a per layout basis, however. If you need to change the layout based on the module, you will have to use a plugin, but you can use the setting in application.ini to set the default layout name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With