Hi,
I've been trying something for quite a while, but I do not know how to implement this and I can't find any information about it.
I have i.e. three classes:
class HeaderController extends BaseController {
public function indexAction() {
$this->view->title = \Phalcon\Tag::getTitle();
$this->view->pick('common/header');
}
}
class FooterController extends BaseController {
public function indexAction() {
$this->view->pick('common/footer');
}
}
class HomeController extends BaseController {
public function indexAction() {
\Phalcon\Tag::setTitle('Home');
$this->view->pick('common/home');
}
}
As you can guess I would like to render the header before the home template and the footer after the home template. However if I in example use Phalcon::setTitle I want to get the right value set in the HomeController.
I know I could use {% extends "templates/base.volt" %} provided by Volt, however I do not wish to have variables append to the view to be shared across different controllers.
I've been playing around with setRenderLevel, render, start and finish, however I can't get it to work.
This is my View in the DI so far:
$di->set('view', function() {
$view = new View();
$view->setBasePath(APP_PATH.'view/');
$view->setViewsDir('');
$view->setRenderLevel(View::LEVEL_BEFORE_TEMPLATE);
$view->render('common/header', 'index');
$view->setRenderLevel(View::LEVEL_AFTER_TEMPLATE);
$view->render('common/footer', 'index');
$view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$view->registerEngines([
".volt" => function($view, $di) {
$volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions([
'compiledPath' => APP_PATH.'cache/volt/',
'compileAlways' => true,
]);
return $volt;
}
]);
return $view;
});