inteve / latte
Latte 模板扩展
v1.0.0
2023-12-08 07:20 UTC
Requires
- php: 7.4 - 8.2
- latte/latte: ^2.9
- nette/di: ^2.4.16
- nette/utils: ^2.5.5 || ^3.0 || ^4.0
- phig/phig: ^1.2
Requires (Dev)
- nette/tester: ^2.4
Conflicts
- nette/php-generator: <3.0
This package is auto-updated.
Last update: 2024-09-14 02:33:05 UTC
README
Latte 模板扩展
安装
composer require inteve/latte
Inteve\Latte 需要 PHP 7.4.0 或更高版本和 Latte 2。
使用方法
安装扩展
\Inteve\Latte\ExtensionInstaller::install($latte, [ new FooExtension, new BarExtension, ]);
或通过 Nette DI 扩展
extensions: inteve.latte: Inteve\Latte\DIExtension services: - FooExtension - BarExtension
IconExtension
创建新的 Latte 标签 {icon foo}
。将图标代码直接保存到编译后的模板中。需要实现 PHIG's HtmlIcons
接口。
\Inteve\Latte\ExtensionInstaller::install($latte, [ new \Inteve\Latte\IconExtension($phigIcons), ]);
{icon myIcon}
TypographyExtension
创建新的 Latte 过滤器 |typography
。
\Inteve\Latte\ExtensionInstaller::install($latte, [ new \Inteve\Latte\TypographyExtension, ]);
{='My a text'|typography} {* prints 'My a text' *}
自定义扩展
只需扩展 Inteve\Latte\Extension
class MyExtension extends \Inteve\Latte\Extension { /** * @return array<callable(\Latte\Compiler):void> */ public function getTags(): array { return [ function (\Latte\Compiler $compiler) { $me = new Latte\Macros\MacroSet($compiler); $me->addMacro('myTag', ['MyLatteMacros', 'macroMyTag']); }, ]; } /** * @return array<string, callable> */ public function getFilters(): array { return [ 'myFilter' => function ($value) { return $value, }, ]; } /** * @return array<string, mixed> */ public function getProviders(): array { return [ 'myProvider' => 'foo bar', ]; } }
许可证:新 BSD 许可证
作者:Jan Pecha,https://www.janpecha.cz/