KTemplate
KTemplate is a simple text template engine for PHP and KPHP
Install / Use
/learn @quasilyte/KTemplateREADME

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.
Related Skills
node-connect
353.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
353.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
353.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
