PHP code example of hengeb / simplates

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: &lt;div style=&quot;position:absolute;display:grid;place-items:center;height:100dvh;background:black;inset:0;color:limegreen;font-size:400%&quot;&gt;Your page is now mine&lt;!--</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'),
]);

<div>current date: <?=$now->format('d.m.Y')

<div>current date: <?=$now->format('d.m.Y', 'Europe/Berlin`)

$templateEngine->set('currentUser', $currentUser);
$templateEngine->set('_timeZone', new \DateTimeZone('Europe/Berlin'));

 $this->extends('layout', ['title' => $user->getName()]); 

<!DOCTYPE html>
<html>
    <head>
        <title><?=$title->raw

<div class="alert"><?=$message></div>


$returnValue = $subject = 'Please confirm your email address';

$body = $templateEngine->render('mail/confirm', [
    'name' => $name,
    'url' => $url,
], $subject);
$mailService->send($address, $subject, $body);

 if ($array): 

 if ($this->check($array)): 

 if ($this->check($array)): 

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()