irfantoor/template-engine
Composer 安装命令:
composer require irfantoor/template-engine
包简介
A simple, small and smart template engine
README 文档
README
A simple and small template engine.
Quick start
Installation
Installation or inclusion in your project:
$ composer require irfantoor/template-engine
To test the template engine:
$ vendor/bin/test
Creating the Template Engine:
$te = new IrfanTOOR\TemplateEngine([ 'max_depth' => 3, # defaults to 3 'base_path' => 'your/path/to/template/files/', ]);
Processing Text
$text = "{$greeting} {$user}!"; $data = [ 'greeting' => 'Hello', 'user' => 'World', ]; echo $te->processText($text, $data);
Processing File
# home.php <h1>{$title}</h1> <ul> {@foreach ($list as $item):} <li>{$item}</li> {@endforeach} </ul>
$data = [ 'title' => 'Fruits', 'list' => [ 'Apple', 'Orange', 'Blackberry', 'Raspberry', ], ]; echo $te->processFile("home.php", $data);
Template
Comments
format: {#...}
{# its a comment!}
{#anything here including the external brackets are removed from the output}
Tokens
format: {$...}
The tokens are replaced with the values provided by the passed data array.
{$name['first']} {$name['last']}
{$address[0]}
{$address[1]}
tel: {$tel}
email: {$email}
format: {!$...} The tokens are replaced with tags are replaced with value, without doing any html special character conversion. It helps in including the html tags etc. which are displayed as html and not as content.
Commands
format: {@...}
{@include 'header.php'}
{@echo date('d-m-Y')}
{@if ($list):}
# Note: you can use the curley brackets, so use the form foreach (...): endforeach instead
{@foreach ($list as $k => $v):}
data provided is : {$k} | {$v}
{@endforeach}
{@endif}
# you can define the data in the template
{@ $d = date('d-m-Y')}
# and prints ...
date : {$d}
# Note: The statement in {@ ...} tags need not to be terminated with a semicolon ';'
{@ $list = [
'black',
'white'
]}
dump list:
# Note: The variable to dump, might as well be an object, array, bool int or a string
{$list}
Note: after {@ use the commands as if you were using the php code, though only constraint is that you can not use the loops or commands using the curly brackets.
irfantoor/template-engine 适用场景与选型建议
irfantoor/template-engine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「template」 「Simple」 「engine」 「fast」 「small」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 irfantoor/template-engine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 irfantoor/template-engine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 irfantoor/template-engine 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple library for make Lexer and Parsers to build a language
A simple library that allows transform any kind of data to native php data or whatever
A simple library that uses the hydration pattern to fill objects given different sources of data.
Micro Active Record library in PHP, support chain calls, events, and relations.
A simple content
Symfony bundle to connect AWS sns and sqs to create offline queue processing
统计信息
- 总下载量: 48
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-19