Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/quasilyte/KTemplate
KTemplate is a simple text template engine for PHP and KPHP
https://github.com/quasilyte/KTemplate
composer-package kphp ktemplate library php template template-engine twig
Last synced: 3 months ago
JSON representation
KTemplate is a simple text template engine for PHP and KPHP
- Host: GitHub
- URL: https://github.com/quasilyte/KTemplate
- Owner: quasilyte
- License: mit
- Created: 2022-08-12T12:09:35.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T16:21:43.000Z (7 months ago)
- Last Synced: 2024-07-05T14:35:59.011Z (4 months ago)
- Topics: composer-package, kphp, ktemplate, library, php, template, template-engine, twig
- Language: PHP
- Homepage:
- Size: 611 KB
- Stars: 6
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![](_docs/logo.png)
## Overview
[KTemplate](https://github.com/quasilyte/KTemplate) is a simple text template engine for PHP and [KPHP](https://github.com/VKCOM/kphp).
KTemplate uses a syntax similar to the Twig, Django and Jinja template languages.
You can try it [online](https://quasilyte.tech/ktemplate/)!
**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
```bash
$ composer require quasilyte/ktemplate
``````php
'{{ title }}',
]);
$engine = new Engine(new Context(), $loader);
$data = new ArrayDataProvider(['title' => 'Example']);
$result = $engine->render('main', $data);
var_dump($result); // => "Example"
```Run with PHP:
```bash
$ php -f example.php
string(7) "Example"
```Run with KPHP:
```bash
# 1. Compile
$ kphp --composer-root $(pwd) --mode cli example.php
# 2. Execute
$ ./kphp_out/cli
string(7) "Example"
```## Documentation
* [Template language overview](_docs/template_language.md)
* [KTemplate idioms](_docs/ktemplate_idioms.md)
* [Differences from Twig](_docs/differences_from_twig.md)
* [KTemplate PHP API](_docs/ktemplate_php_api.md)
* [KTemplate architecture](_docs/ktemplate_architecture.md)## Rationale
None of the template engines for PHP can be used with KPHP.
KTemplate is a solution that works in both languages.