2
votes

Building an application in Phalcon, I am struggling for couple of hours to set the different layout for admin other than main layout.

My controller is AdminController, I have created a file views/layouts/admin.volt but I still see the main layout applied although I have set layout in initialize function of AdminController using $this->view->setLayout('admin');

1
Probably your answer here: stackoverflow.com/questions/23582196/override-layout-in-phalcon as you can see in comment: Thank you unforunatly my problem was with the relative directory ;) - stepozer
$this->view->setTemplateBefore('admin') - David Duncan

1 Answers

2
votes

You need to remove your layout views/index.phtml and place it inside views/layouts/index.phtml

Then you can switch your layout from index to custom or any other using:

$layout = 'anonymous';

if ($this->session->has('user')) {
    $layout = 'index';
}

$this->view->setLayout($layout);

Phalcon loads in first place views/index.phtml, then it writes the content found in views/layouts/index.phtml (related to your controller) and finally it writes your views/index/index.phtml (related to your action HTML content)