Created
December 2, 2009 14:30
-
-
Save sirupsen/247233 to your computer and use it in GitHub Desktop.
Simple templating engine in PHP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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