Initial commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
/nbproject/
|
||||
/vendor/
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "kavalanche/template",
|
||||
"description": "Simple templating system",
|
||||
"type": "library",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Wojtek",
|
||||
"email": "w.lk@wp.pl"
|
||||
}
|
||||
],
|
||||
"require": {},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Kavalanche\\Template\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Kavalanche\Template;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @author Wojciech Burda <w.lk@wp.pl>
|
||||
*/
|
||||
class View {
|
||||
|
||||
private $templateDirectory;
|
||||
|
||||
public function __construct($templateDirectory) {
|
||||
$this->templateDirectory = $templateDirectory;
|
||||
}
|
||||
|
||||
public function render($view, array $data, $base = null) {
|
||||
extract($data);
|
||||
|
||||
if ($base) {
|
||||
if (!file_exists($this->templateDirectory . '/' . $base . '.php')) {
|
||||
throw new Exception('Base template not found!');
|
||||
}
|
||||
ob_start();
|
||||
require $this->templateDirectory . '/' . $view . '.php';
|
||||
$content = ob_get_clean();
|
||||
|
||||
require $this->templateDirectory . '/' . $base . '.php';
|
||||
} else {
|
||||
require $this->templateDirectory . '/' . $view . '.php';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user