Reorder and change some methods visibility in Template and Layout

This commit is contained in:
Giuseppe Criscione 2019-05-14 15:57:54 +02:00
parent 9f518cbf56
commit 7ed745333a
2 changed files with 53 additions and 53 deletions

View File

@ -54,7 +54,7 @@ class Layout extends Template
*
* @return string|null
*/
protected function content()
public function content()
{
return $this->content;
}

View File

@ -124,6 +124,58 @@ class Template
return $this->scheme = new Scheme($this->name);
}
/**
* Get Assets instance
*
* @return Assets
*/
public function assets()
{
if (!is_null($this->assets)) {
return $this->assets;
}
return $this->assets = new Assets(
$this->path() . 'assets' . DS,
Formwork::instance()->site()->uri('/templates/assets/', false)
);
}
/**
* Set template layout
*
* @param string $name
*/
public function layout($name)
{
if (!is_null($this->layout)) {
throw new RuntimeException('The layout for ' . $this->name . ' template is already set');
}
$this->layout = new Layout($name, $this->page, $this);
}
/**
* Insert a template
*
* @param string $name
* @param array $vars
*/
public function insert($name, array $vars = array())
{
if ($name[0] === '_') {
$name = 'partials' . DS . substr($name, 1);
}
$filename = $this->path() . $name . $this->extension;
if (!FileSystem::exists($filename)) {
throw new RuntimeException('Template ' . $name . ' not found');
}
extract(array_merge($this->vars, $vars));
include $filename;
}
/**
* Render template
*
@ -204,58 +256,6 @@ class Template
}
}
/**
* Get Assets instance
*
* @return Assets
*/
protected function assets()
{
if (!is_null($this->assets)) {
return $this->assets;
}
return $this->assets = new Assets(
$this->path() . 'assets' . DS,
Formwork::instance()->site()->uri('/templates/assets/', false)
);
}
/**
* Set template layout
*
* @param string $name
*/
protected function layout($name)
{
if (!is_null($this->layout)) {
throw new RuntimeException('The layout for ' . $this->name . ' template is already set');
}
$this->layout = new Layout($name, $this->page, $this);
}
/**
* Insert a template
*
* @param string $name
* @param array $vars
*/
protected function insert($name, array $vars = array())
{
if ($name[0] === '_') {
$name = 'partials' . DS . substr($name, 1);
}
$filename = $this->path() . $name . $this->extension;
if (!FileSystem::exists($filename)) {
throw new RuntimeException('Template ' . $name . ' not found');
}
extract(array_merge($this->vars, $vars));
include $filename;
}
public function __call($name, $arguments)
{
if (TemplateHelpers::has($name)) {