better templating

This commit is contained in:
Gilles Crettenand
2015-06-02 22:21:17 +02:00
parent 65f0dfe71f
commit af4c9e77c8
3 changed files with 16 additions and 13 deletions

View File

@@ -97,12 +97,14 @@ class Html extends Formatter {
);
}
$html = file_get_contents('template.html');
$panel = static::template($context, 'panel');
echo static::template(array('title' => $context['title'], 'content' => $panel));
}
foreach($context as $k => $v) {
$html = str_replace("{{ $k }}", $v, $html);
}
public static function template(array $context = array(), $template = 'layout') {
$html = file_get_contents(sprintf('templates/%s.html', $template));
echo $html;
$patterns = array_map(function($p) { return "{{ $p }}"; }, array_keys($context));
return str_replace($patterns, array_values($context), $html);
}
}