alexkuusk / malli
本包最新版本(v0.1)没有提供许可证信息。
精简PHP模板解析器
v0.1
2024-02-10 18:37 UTC
Requires
- php: >=8.2
README
A simple and lightweight PHP templating engine using few custom tags that all are translated into pure PHP. PHP is also allowed inside templates, just be aware of the scopes. Template blocks are compiled into PHP functions and functions are called and their output captured.
Possibility to add custom tags, for example translation code. That code's output can be turned into static and saved along with PHP code, so that heavy translating functions are not called every page load. Supports multilanguage and multisite, just pass language parameter and use dynamic path with another set of templates ('path' => '../tpl/' . $_SERVER['SERVER_NAME'] . '/').
Blocks can be nested inside blocks.
需要PHP版本8.2+
配置
更多复杂示例请参阅示例文件夹
composer install alexkuusk/malli
最小化
require_once '../vendor/autoload.php'; use Alexkuusk\Malli\Malli; echo (new Malli([ '_params' => [ 'path' => '../tpl/', 'file' => 'index.tpl', 'block' => 'index', //if omitted, file name without extension is used ], '_data' => [ 'title' => 'Template test', 'books' => [ 'One', 'two', ] ]));
index.tpl
{{ BLOCK:index }} <html> <head> <title>{{ $title }}</title> </head> <body> <table border=1> {{ FOREACH $books as $k => $title }} <tr> <td>{{ $k + 1 }}</td> <td>{{ htmlspecialchars($title) }}</td> </tr> {{ /FOREACH }} </table> </body> </html> {{ /BLOCK:index }}