zvax / templating
一个简单的 PHP 模板解析器
2.0.0
2023-01-19 07:32 UTC
Requires
- php: >=8.1
- twig/twig: ^2.11
- zvax/storage: ^2.0
Requires (Dev)
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
README
大部分是废弃的项目,用于渲染接口和 Twig 适配器,以便我在其他项目中使用。
以下内容仍然有一定的真实性。
简单的模板解析引擎
引擎是解析器,它将正则表达式模板字符串并替换键为值
$templateString = '{first}{$second}{$obj->third}'; $engine = new Engine(); $obj = new stdClass(); $obj->third = 'sentence.'; $string = $engine->render($templateString,[ 'first' => 'This ', 'second' => 'is a ', 'obj' => $obj, ]); // This is a sentence.
有非常基本的循环支持
$string = $engine->render('{foreach $posts as $post}{$post}{/foreach}',[ 'posts' => [ 'post1', 'post2', ], ]); // post1post2
posts 数组必须是一个 0 索引的字符串容器