Any Text Format
CSV, XML, JSON, YAML, TOML, HTML, Markdown, INI, XSD, or custom formats - Tsuku handles them all
A lightweight PHP templating library built with clean Lexer → Parser → Compiler architecture
Transform your data into any format with simple, intuitive templates:
use Qoliber\Tsuku\Tsuku;
$tsuku = new Tsuku();
$template = 'SKU,Name,Price,Stock
@for(products as product)
@csv(product.sku),@csv(product.name),@number(product.price, 2, ".", ""),{product.stock}
@end';
$data = [
'products' => [
['sku' => 'WID-001', 'name' => 'Widget', 'price' => 29.99, 'stock' => '100'],
['sku' => 'GAD-002', 'name' => 'Gadget, Premium', 'price' => 1299.50, 'stock' => '50'],
],
];
echo $tsuku->process($template, $data);Output:
SKU,Name,Price,Stock
WID-001,Widget,29.99,100
GAD-002,"Gadget, Premium",1299.50,50@csv() quotes the name that contains a comma, and @number(price, 2, ".", "") keeps the thousands separator out of the price column.
and / &&, or / ||, not / !, parentheses and in / not in in @if, @unless, @elseif and @?{...} (Conditionals)@elseif branches with a single @endregisterDirective() now works: @cdata ... @end, @wrap("[", "]") ... @end (Custom Directives)@@ prints a literal @ - user@@example.com, @@media (...) (Escapes & Special Characters)ParseException with line and column instead of rendering something wrongprocessToStream() for feeds with hundreds of thousands of rows (Streaming)1.4.0 changes some output compared to 1.3.0 (mostly whitespace around directives) - read Upgrading from 1.3 before you update, and the Changelog for everything else.
1.4.1 is a bug-fix release: warnings of a per-call strictness mode can be read, functions that throw inside conditions follow the strictness mode, @substr() and friends accept numbers from the data, \" is a quote inside a quoted string, uncallable function names are refused when registered, and registerFormatter() works. See Upgrading to 1.4.1.
1.4.2 fixes three more: @csv() quotes a value holding a carriage return, a quoted function argument or @?{...} value may span lines, and WARNING mode keeps at most 1,000 warnings per call so streaming memory stays bounded (getWarningCount() has the total). See Upgrading to 1.4.2.
Tsuku excels at transforming structured data into various text formats - CSV exports, XML feeds, JSON APIs, configuration files, and more. Unlike HTML-focused template engines (Twig, Blade), Tsuku is designed specifically for data transformation.
Built with a clean three-stage compiler pipeline:
The same architecture used by programming languages like PHP itself, JavaScript, and Python.
Tsuku 1.4.1 ships with 944 tests, 99.4% line coverage and a 98.8% mutation score. Characterization tests pin the 1.3.0 behaviour that 1.4 keeps.
composer require qoliber/tsuku