lkt/templates
Composer 安装命令:
composer require lkt/templates
包简介
LKT PHP Template
README 文档
README
It's simple. It's fast. It's LKT Templates!
Are you tired of complex PHP template engine?
Would you like to code just like in regular PHP?
Then this lib is for you!
Installation
composer require lkt/templates
Usage
The layout file
LKT Templates works with PHTML/PHP files.
In a PHTML file you can do anything you can do with PHP, just remember the colon syntax.
For example, take this layout.phtml file:
<div><?php echo $title; ?></div> <?php foreach ($data as $datum): ?> <div><?php echo $datum; ?></div> <?php endforeach; ?> <?php if(isset($favouriteDrink)): ?> <div>Favourite drink: <?php echo $favouriteDrink; ?></div> <? endif; ?>
You may be asking where the data came from? That's what follows
The Template instance: Access to the layout
This is how you access to layout.phtml:
use Lkt\Templates\Template; // Create a template instance: $template = Template::file('layout.phtml'); // You can set a relative path, but absolute path it's allowed too // Feed the data $template->setData([ 'title' => 'Hello from LKT Templates!', 'data' => [1,2] ]); // If you want to, you can add more data with: $template->set('favouriteDrink', 'Apple juice'); // PEGI 3+ example // Parse the layout $html = $template->parse(); // String returned // And now you can just print the html or do whatever you want to do with that string echo $html; // Alternatively, you can just print the template, and it will be automatically parsed: echo $template; // equal to echo $template->parse();
The generated HTML
The layout used in this readme feed with data as shown in the PHP example will print something like this:
<div>Hello from LKT Templates!</div> <div>1</div> <div>2</div> <div>Favourite drink: Apple juice</div>
Additional notes
Access a template file with constant path:
$template = Template::file(__DIR__ . '/path/to/layout.phtml');
lkt/templates 适用场景与选型建议
lkt/templates 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 229 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lkt/templates 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lkt/templates 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 229
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-04