inventor96/mako-template-pp
Composer 安装命令:
composer require inventor96/mako-template-pp
包简介
Mako Template++. Additional filters I use within the Mako templating system, with the ability to register more.
README 文档
README
Additional filters I use within the Mako templating system, with the ability to register more.
Installation
-
Install the composer package:
composer require inventor96/mako-template-pp
-
Enable the package in Mako:
app/config/application.php:[ 'packages' => [ 'web' => [ \inventor96\MakoTemplatePP\TemplatePackage::class ], ], ];This will automatically register the
TemplatePPclass in the Mako View Factory as the default renderer for.tpl.phpfiles.
Configuration
Configuration options are available for only the time filter at this time. To customize these options, create a configuration file at app/config/packages/templatepp/template.php with the following structure:
<?php return [ /** * The `time:` template filter. */ 'time' => [ /** * The format to use when displaying date/time values. * Defaults to 'D, j M Y g:i:s a T'. */ 'format' => 'D, j M Y g:i:s a T', /** * The string to display when the date/time value is empty. * Defaults to '---'. */ 'empty_replacement' => '---', ], ];
Usage
Available Filters
{{ route: <route_name> [, <param>, ...] }}
Generates a URL for a named route defined in the Mako routing system. Accepts additional parameters to fill in route placeholders. This ensures that URLs are generated consistently and correctly throughout the application.
{{ time: <timestamp> [, <format>] [, <empty_replacement>] }}
Formats a given timestamp into a human-readable date/time string, as defined by the time filter configuration. Data types include DateTime, Mako's Time, string, false, and null. The format can be overridden by providing the second parameter. If the timestamp evaluates to empty(), the empty replacement string will be used, as defined in the configuration, or the value of the third parameter. This is useful for displaying dates and times in a consistent format across the application.
{{ pluralize: <noun> [, <count>] }}
Alias of Mako's Str::pluralize() method.
{{ part: <partial_name> [, <param>, ...] }}
Alias to {{ view: 'partials.<partial_name>' [, <param>, ...] }}, allowing new lines for code readability. Renders a partial template located in the app/resources/views/partials/ directory. This helps to keep templates modular and reusable.
{{ up: {{ ... }} }}
Mark code for "filtering up" the compiled PHP so it can be part of a parameter in another template tag. This is particularly useful when you need to pass dynamic values to template params that require PHP code. e.g. {{ route: 'route.name', [ 'param' => {{ up: {{ pluralize: 'value' }} }} ] }}.
Creating Custom Filters
Simple Filters
To create and register custom template filters, you need to use the FilterRegistry class provided by this package. You can register the filters anywhere the Mako container is available (e.g. in the bootstrap.php file, in a service class, in a controller, etc.). Below is an example of how to use a service class to create a custom filter that converts a string to uppercase.
namespace app\services; use inventor96\MakoTemplatePP\FilterRegistry; use mako\application\services\Service; class UppercaseTemplateFilter extends Service { /** * Registers the service. */ public function register(): void { // get the FilterRegistry from the container $registry = $this->container->get(FilterRegistry::class); // register the 'uppercase' filter $registry->registerFilterCallback('uppercase', function ($string) { return strtoupper($string); }); } }
Then, enable the service in your application.php config:
[ 'services' => [ 'core' => [ app\services\UppercaseTemplateFilter::class, ], ], ];
You can now use the uppercase filter in your templates:
{{ uppercase: 'hello world' }} <!-- Outputs: HELLO WORLD -->
Advanced Filters
For more complex filters that require additional setup or dependencies, you can use the registerCompilerHandler() and registerRenderMethod() methods of the FilterRegistry class. These methods allow you to define custom compiler handlers and render methods for your filters. Compiler handlers are used to convert the template syntax into PHP code. Render methods are called during each render of the compiled PHP template. Refer to the method docblocks in FilterRegistry for more details. See also the mako\view\compilers\Template and mako\view\renderers\Template classes for reference on how Mako's templating system works.
inventor96/mako-template-pp 适用场景与选型建议
inventor96/mako-template-pp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「templating」 「template」 「engine」 「preprocessor」 「mako」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 inventor96/mako-template-pp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 inventor96/mako-template-pp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 inventor96/mako-template-pp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
A SilverStripe module to optimise the Meta, crawling, indexing, and sharing of your website content (forked from Cyber-Duck/Silverstripe-SEO)
A Processor for Markup written in PHP. Allows extraction of Markup into a data structure, orchestrated nested manipulation of said structure, and output as (optimized) Markup.
Allow KoolReport to use twig template engine to render view
Simple template engine
Simple ASCII output of array data
统计信息
- 总下载量: 39
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-25