KTemplate is a simple text template engine for PHP and KPHP
MIT License
KTemplate is a simple text template engine for PHP and KPHP.
KTemplate uses a syntax similar to the Twig, Django and Jinja template languages.
You can try it online!
Features:
$ composer require quasilyte/ktemplate
<?php
require_once __DIR__ . '/vendor/autoload.php';
use KTemplate\Context;
use KTemplate\Engine;
use KTemplate\ArrayLoader;
use KTemplate\ArrayDataProvider;
$loader = new ArrayLoader([
'main' => '{{ title }}',
]);
$engine = new Engine(new Context(), $loader);
$data = new ArrayDataProvider(['title' => 'Example']);
$result = $engine->render('main', $data);
var_dump($result); // => "Example"
Run with PHP:
$ php -f example.php
string(7) "Example"
Run with KPHP:
# 1. Compile
$ kphp --composer-root $(pwd) --mode cli example.php
# 2. Execute
$ ./kphp_out/cli
string(7) "Example"
None of the template engines for PHP can be used with KPHP.
KTemplate is a solution that works in both languages.