Skip to content

Instantly share code, notes, and snippets.

@chernomyrdin
Created November 21, 2012 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chernomyrdin/4124075 to your computer and use it in GitHub Desktop.
Save chernomyrdin/4124075 to your computer and use it in GitHub Desktop.
Small template engine for PHP
<?php
class Template {
private $vars = array();
private $file = null;
function __construct ($file = null, $vars = null) {
$this->file = $file;
if (!is_null($vars)) {
$this->vars = $vars;
}
}
function __set ($name, $value) {
return $this->vars[$name] = $value;
}
function __get ($name) {
return $this->vars[$name];
}
function __toString () {
if (is_null($this->file)) {
return '';
}
extract($this->vars);
ob_start();
include($this->file);
return ob_get_clean();
}
function render ($file) {
$this->file = $file;
return $this;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment