Skip to content

Instantly share code, notes, and snippets.

@DanielVF
Created January 19, 2010 13:52
Show Gist options
  • Save DanielVF/280938 to your computer and use it in GitHub Desktop.
Save DanielVF/280938 to your computer and use it in GitHub Desktop.
PHP template engine for emailing form results.
// PHP template engine for emailing form results.
class LionbackTemplate{
function LionbackTemplate($template,$data){
$this->template=$template;
$this->data=$data;
}
function render(){
$content = file_get_contents($this->template);
$out = preg_replace_callback('/\{\{([^}]+)\}\}/',array(&$this,'render_value_callback'),$content);
return $out;
}
function render_value_callback($match){
$name = $match[1];
$value = $this->data[$name];
if(strpos($name,'_checkbox')>0){
if($value!=''){
return '<input type="checkbox" checked="True" name="y" value="Y">';
}else{
return '<input type="checkbox">';
}
}elseif(strpos($name,'_radio_')>0){
list($name,$key) = explode('_radio_',$name);
$value = $this->data[$name];
$checked = $key == $value ? 'checked' : '';
return '<input type="radio" '.$checked.'>';
}else{
return '<span style="text-decoration:underline;">'.htmlspecialchars($value).'</span>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment