Templating that's just PHP. That's it. Seriously.
Support using pure PHP templates with automatic XSS mitigation.
composer require phpolar/pure-php
$page = new Page();
$safeContext = new HtmlSafeContext($page);
$templateEng->render("path/to/template.php", $safeContext);
// or...
echo $templateEng->apply("path/to/template", $safeContext /* optional */);
// or...
echo $templateEng->apply("template", $safeContext /* optional */);
// or...
echo $templateEng->apply("template", $safeContext /* optional */);
The template engine will look for files with .php, .phtml, or .html extensions in
src/templates
directory relative to the current working directory.
// template.php
<!DOCTYPE html>
<?php
/**
* @var Page $view
*/
$view = $this;
?>
<html>
<head>
<style>
body {
font-family: <?= $view->font ?>;
padding: 0;
margin: 0;
}
form th {
text-align: right;
}
form td {
text-align: left;
}
.container {
background-color: <?= $view->backgroundColor ?>;
padding: 20px 0 90px
}
</style>
</head>
<body style="text-align:center">
<h1><?= $view->title ?></h1>
<div class="container">
</div>
</body>
</html>
// Page.php
class Page
{
public string $title;
public string $backgroundColor = "#fff";
public string $font = "Arial";
public function __construct(string $title)
{
$this->title = $title;
}
}