inteve/latte

Latte 模板扩展

资助包维护!
其他

v1.0.0 2023-12-08 07:20 UTC

This package is auto-updated.

Last update: 2024-09-14 02:33:05 UTC


README

Build Status Downloads this Month Latest Stable Version License

Latte 模板扩展

Donate

安装

下载最新包下载最新包或使用Composer

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/