jelix/castor
Composer 安装命令:
composer require jelix/castor
包简介
A template engine using a simple syntax
关键字:
README 文档
README
Castor is a template engine for PHP, using syntax similar to PHP.
Features
- A simple Api to inject data and to generate content
- A language with a syntax similar to PHP, but a bit simpler to ease learning
- Templates can be a file or a simple string
- Efficient generator: template files are "compiled" to PHP files
- A sandbox mode, to fetch untrusted templates (templates uploaded by a user in a CMS for example). This mode has less capabilities of course.
- A plugin system
- Plugins can be specific to a content type (HTML, XML, text…), so they produce right contents.
- a system of “meta”: allow the template to expose data to PHP code. For example, a "meta" can be an url of a stylesheet to use with the generated content.
Compatible with PHP 7.4 to 8.5.
Version
The master branch is the development branch. It has sources of the next major version 2.0.0.
There are many breaking changes on the API compared to the 1.x version. It has also a new plugin system. See CHANGELOG_V2.md for more details.
See the branch 1.x for the last stable version, used in the Jelix Framework 1.8.
Installation
You can install it from Composer. In your project:
composer require "jelix/castor"
Usage
A template file test.ctpl:
{! autoescape !}
<h1>{{ $titre|upper }}</h1>
<ul>
{% foreach $users as $user %}
<li>{{$user->name}} ({{$user->birthday|datetime:'d/m/Y'}})
<div>{{$user->biography|raw}}</div>
</li>
{% endforeach %}
</ul>
The PHP code:
// directory where compiled templates are stored $cachePath = realpath(__DIR__.'/temp/') . '/'; // directory where templates can be found $templatePath = __DIR__.'/'; // create a configuration object. See its definition to learn about all of its options $config = new \Jelix\Castor\Config($cachePath, $templatePath); // let's create a template engine $tpl = new \Jelix\Castor\Castor($config); // assign some values, so they will be available for the template $users = array( // User in an example class... new User('Tom', '2001-02-01'), new User('Laurent', '1990-03-01'), new User('Bob', '1970-05-25') ); $tpl->assign('users', $users); $tpl->assign('titre', 'This is a test !'); // content is generated from the given template file and returned $content = $tpl->fetch('test.ctpl'); // or content is generated from the given template file and sent directly to the browser $tpl->display('test.ctpl');
To know more, see the docs/ directory.
History
Castor was formerly known as jTpl and was used in the Jelix Framework since 2006. There was a specific version, "jTpl standalone", existing for years to use jTpl without Jelix, but it was never released as a stable version.
In 2015, jTpl was completely "extracted" from Jelix (starting to Jelix 1.7), and is now available as a standalone component under the name "Castor", with true stable releases.
jelix/castor 适用场景与选型建议
jelix/castor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 115.74k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「template」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jelix/castor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jelix/castor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jelix/castor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple ASCII output of array data
E2E Studios PHP Framework adaptation of leafsphp/blade package
Ensolab template project
Account Balance / Wallets Manager For FilamentPHP and Filament Account Builder
Render blade templates into a PSR-7 Response object.
A PDF builder using HTML or DOCX templates.
统计信息
- 总下载量: 115.74k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 27
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: LGPL-2.1
- 更新时间: 2015-05-27