1. Go to this page and download the library: Download affinity4/template 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/ */
affinity4 / template example snippets
use Affinity4\Template;
$template = new Template\Engine(new Template\Syntax);
$tempalte->render('views/home.php', ['page_title' => 'Home']);
use Affinity4\Template;
$template = new Template\Engine(new Template\Syntax);
$template->render('views/home.php', ['title' => 'Home Page']);
use Affinity4\Template;
$template = new Template\Engine(new Template\Syntax);
$template->addRule('/\{\{ ([\w\d+]) \}\}/', '<?= $$1
use Affinity4\Template;
$template = new Template\Engine(new Template\Syntax);
$template->addRule('/\{\{ ([\w\d]+) \}\}/', function ($statement) {
return ' echo $' . $statement[1] . '
namespace Your\Template\Syntax\Blade2;
use Affinity4\Template;
class Blade2 extends Affinity4\Template\Tokenizer implements Affinity4\Template\SyntaxInterface
{
public function __construct()
{
$this->addRule('/\{\{ ?(\$.*) ?\}\}/', ' echo htmlspecialchars($1, ENT_QUOTES, 'UTF-8');
use Affinity4\Template\Engine;
use Your\Template\Syntax\Blade2;
$blade2 = new Engine(new Blade2);
$blade2->render('views/home.blade', ['title' => 'Blade 2']);
html
<!-- @if :showTitle is true and :something is false or :somethingElse -->
<h1><!-- :title --></h1>
<!-- @/if -->
<!-- @if :showTitle -->
<h1><!-- :title --></h1>
<!-- @elseif :something and :showTitle -->
<h1><!-- :title --></h1>
<h2>Something</h1>
<!-- @else -->
<h1>Default Title</h1>
<!-- @/if -->
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.