Skip to content

Instantly share code, notes, and snippets.

@sirupsen
Created December 2, 2009 14:30
Show Gist options
  • Save sirupsen/247233 to your computer and use it in GitHub Desktop.
Save sirupsen/247233 to your computer and use it in GitHub Desktop.
Simple templating engine in PHP.
<?php
/*
*
* Simple template engine
*
*/
class Template {
private $data;
/*
*
* Put a variable into the template.
*
* @param string $name Name of the value
* @param mixed $data Value/data
*
*/
public function __set($name, $data) {
$this->data[$name] = $data;
}
/*
*
* When the object is converted to an object,
* write the template out.
*
*/
public function __toString() {
// Extract the $data array into variables
extract($this->data);
// Require the view file
require('view.php');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment