Added Controller_Template clone with a default view class and template
This commit is contained in:
parent
706b94e9ad
commit
3f283b65d5
42
classes/controller/kostache.php
Normal file
42
classes/controller/kostache.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
abstract class Controller_Kostache extends Controller {
|
||||
|
||||
/**
|
||||
* @var string page template
|
||||
*/
|
||||
public $template = 'template';
|
||||
|
||||
/**
|
||||
* @var boolean auto render template
|
||||
**/
|
||||
public $auto_render = TRUE;
|
||||
|
||||
/**
|
||||
* Loads the template [View] object.
|
||||
*/
|
||||
public function before()
|
||||
{
|
||||
if ($this->auto_render === TRUE)
|
||||
{
|
||||
// Load the template
|
||||
$this->template = Walrus::factory($this->template);
|
||||
}
|
||||
|
||||
return parent::before();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the template [View] as the request response.
|
||||
*/
|
||||
public function after()
|
||||
{
|
||||
if ($this->auto_render === TRUE)
|
||||
{
|
||||
$this->request->response = $this->template;
|
||||
}
|
||||
|
||||
return parent::after();
|
||||
}
|
||||
|
||||
} // End Controller_Kostache
|
15
classes/view/template.php
Normal file
15
classes/view/template.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class View_Template extends Kostache {
|
||||
|
||||
/**
|
||||
* @var string template title
|
||||
*/
|
||||
public $title = 'Brought to you by KOstache!';
|
||||
|
||||
/**
|
||||
* @var string template content
|
||||
*/
|
||||
public $content = 'Hello, world!';
|
||||
|
||||
} // End View_Template
|
11
templates/template.mustache
Normal file
11
templates/template.mustache
Normal file
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>{{title}}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{title}}</h1>
|
||||
<p>{{content}}</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue