safer-blitz
A small extension to Blitz template engine,
adding template inheritance and auto-escaping.
Template inheritance
article.tpl:
<article>text</article>
layout.tpl:
<header/>
{{ raw(content) }}
<footer/>
PHP code:
$view = new View("article.tpl");
$view->extend("layout.tpl");
echo $view->parse();
The output:
<header/>
<article>text</article>
<footer/>
Auto-escaping
Initialize view:
$view = new \SaferBlitz\View;
In template:
{{ $some_variable }}
In controller:
$view->set(["some_variable" => "some nasty XSS attempt: \"><script>alert(\"XSS\");</script>"]);
$view->display();
Result:
some nasty XSS attempt: "><script>alert("XSS");</script>
To output variable unescaped, use _raw($var)_ template API:
{{ raw($trusted_variable) }}
If anyone appears to be interested in this project, I will probably add proper escape methods to escape attributes, CSS, JS. For now, this is out of my personal scope of use though.