1

if i have 2 layout in my application how can change my default layout to other layout for some controller or action?

ulduz114
  • 1,150
  • 6
  • 21
  • 37

3 Answers3

7

robertbasic's answer is correct. You can also do the following inside of a controller action:

$this->_helper->layout->setLayout('otherlayout');
Mark
  • 6,254
  • 1
  • 32
  • 31
2

Here you go:

$layout = Zend_Layout::getMvcInstance();
$layout->setLayout('otherlayout');

Where otherlayout is the name of the second layout (otherlayout.phtml in your layouts folder).

robertbasic
  • 4,325
  • 1
  • 27
  • 25
1

On my opinion, It is better to use

$layout = Zend_Layout::getMvcInstance();
$layout->setLayout('otherlayout');

in your view rather than use

$this->_helper->layout->setLayout('otherlayout');

from the controller.

The latter method has a bug. I had an experience where I used

$this->_helper->layout->setLayout('otherlayout');

and the new layout was displayed inside the old layout. I used

$layout = Zend_Layout::getMvcInstance();
$layout->setLayout('otherlayout');

then it worked

swapnesh
  • 26,318
  • 22
  • 94
  • 126
jahkey
  • 11
  • 1