mirror of
https://github.com/getformwork/formwork.git
synced 2025-02-24 09:42:43 +01:00
Load templates on each template rendering, not only for the current page
This commit is contained in:
parent
21573b04d2
commit
045ae83aaa
@ -197,8 +197,6 @@ class Formwork
|
||||
|
||||
$resource = $this->router->dispatch();
|
||||
|
||||
$resource->template()->loadController();
|
||||
|
||||
if (is_null($this->site->currentPage())) {
|
||||
$this->site->setCurrentPage($resource);
|
||||
}
|
||||
|
@ -122,6 +122,15 @@ class Template
|
||||
|
||||
$this->vars = array_merge($this->vars, $vars);
|
||||
|
||||
$isCurrentPage = $this->page->isCurrent();
|
||||
|
||||
$this->loadController();
|
||||
|
||||
// Render correct page if the controller has changed the current one
|
||||
if ($isCurrentPage && !$this->page->isCurrent()) {
|
||||
return Formwork::instance()->site()->currentPage()->template()->render($vars, $return);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
$this->rendering = true;
|
||||
@ -146,23 +155,6 @@ class Template
|
||||
ob_end_flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template controller if exists
|
||||
*/
|
||||
public function loadController()
|
||||
{
|
||||
if ($this->rendering) {
|
||||
throw new RuntimeException(__METHOD__ . ' not allowed while rendering');
|
||||
}
|
||||
|
||||
$controllerFile = $this->path . 'controllers' . DS . $this->name . '.php';
|
||||
|
||||
if (FileSystem::exists($controllerFile)) {
|
||||
extract($this->vars);
|
||||
$this->vars = array_merge($this->vars, (array) include $controllerFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array containing the default data
|
||||
*
|
||||
@ -177,6 +169,23 @@ class Template
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template controller if exists
|
||||
*/
|
||||
protected function loadController()
|
||||
{
|
||||
if ($this->rendering) {
|
||||
throw new RuntimeException(__METHOD__ . ' not allowed while rendering');
|
||||
}
|
||||
|
||||
$controllerFile = $this->path . 'controllers' . DS . $this->name . '.php';
|
||||
|
||||
if (FileSystem::exists($controllerFile)) {
|
||||
extract($this->vars);
|
||||
$this->vars = array_merge($this->vars, (array) include $controllerFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Assets instance
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user