1. Go to this page and download the library: Download hengeb/simplates library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hengeb / simplates example snippets
$templateEngine = new \Hengeb\Simplates\Engine('/path/to/your/templates');
echo $templateEngine->render('user/profile', [
'name' => 'Bob',
'hobbys' => '<div style="position:absolute;display:grid;place-items:center;height:100dvh;background:black;inset:0;color:limegreen;font-size:400%">Your page is now mine<!--',
]);
<h3><?=$name></h3>
<div>My Hobbys are: <?=$hobbys
<h3>Bob</h3>
<div>My Hobbys are: <div style="position:absolute;display:grid;place-items:center;height:100dvh;background:black;inset:0;color:limegreen;font-size:400%">Your page is now mine<!--</div>
<?=$hobbys->raw()
class User {
public function __construct(public string $name, public string $hobbys)
{
}
public function getName(): string
{
return $this->name;
}
public function getHobbys(): string
{
return $this->hobbys;
}
}
echo $templateEngine->render('user/list', [
'users' => [
new User('Alice', 'Coding'),
new User('Bob', '<script>hijackPage();</script>'),
],
]);
if(count($users) === 0):
echo $templateEngine->render('now', [
'now' => new \DateTimeImmutable('now'),
'_timeZone' => new \DateTimeZone('Europe/Berlin'),
]);
class TemplateVariable extends \Hengeb\Simplates\TemplateVariable
{
public function bold(): string
{
return "<span style='font-weight:bold'>" . $this->__toString() . "</span>";
}
}
// connect the extension to the engine
\Hengeb\Simplates\Engine::$proxyClass = TemplateVariable::class;
Hello, <?=$name->bold()
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.