if i have 2 layout in my application how can change my default layout to other layout for some controller or action?
Asked
Active
Viewed 1,845 times
3 Answers
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
-
@Mark +1 still working, mine version is v1.11.11 :) upvoted :) – swapnesh Jan 09 '13 at 09:16
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