quasilyte / ktemplate
v0.8.1
2024-04-02 18:45 UTC
Requires
- vkcom/kphp-polyfills: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- vkcom/kphpunit: ^1.0
- vkcom/ktest-script: ^0.7.4
This package is not auto-updated.
Last update: 2024-11-13 19:16:29 UTC
README
Overview
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:
- Cross-language support: works for both PHP and KPHP
- Security: no eval or dynamic PHP code generation/loading is used
- Compile-time checks: many errors are caught during template compilation
- Zero-copy data binding: efficient and flexible data provider model
- Performance: templates are compiled to optimized bytecode
Quick Start
$ 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"
Documentation
- Template language overview
- KTemplate idioms
- Differences from Twig
- KTemplate PHP API
- KTemplate architecture
Rationale
None of the template engines for PHP can be used with KPHP.
KTemplate is a solution that works in both languages.