webchemistry/component-macro

此包的最新版本(2.0)没有可用的许可信息。

2.0 2017-06-08 13:52 UTC

This package is auto-updated.

Last update: 2024-09-08 22:47:10 UTC


README

用更美观、更简短的方式替换了include,从nette导入。

Build Status

安装

	WebChemistry\Macros\ComponentMacro::install($latte->getCompiler(), __DIR__ . '/component-dir');

使用单个文件

	<Template n:component />

~ 与nette相同

	{include __DIR__ . '/component-dir/template.latte'}

从component-dir/template.latte渲染内容

使用单个文件,多个块

	<TemplateFirst block n:component /> <!-- Renders block 'first' -->
	<TemplateSecond block n:component="key => value" /> <!-- Renders block 'second' -->

与nette相同

{import __DIR__ . '/component-dir/template.latte'}

{include #first}
{include #second key => value}

template.latte

{define first}
    ...
{/define}

{define second}
    {$key}
    ...
{/define}

使用其他目录的文件

    <TemplateFirst n:component />

与nette相同

{include __DIR__ . '/component-dir/template/first.latte'}

template/first.latte

...

自定义参数

	<Template n:component="foo => bar" />

与nette相同

	{include __DIR__ . '/component-dir/template.latte' foo => bar}

template.latte

	{$foo}

内容

	<Template n:component>
		Content with dynamic parameter or with macros <Template n:component />
	</Template>

与nette相同

{capture $foo}
	Content with dynamic parameter or with macros {include __DIR__ . '/component-dir/template.latte'}
{/capture}
{include __DIR__ . '/component-dir/template.latte' _content => $foo}

template.latte

{!$_content}

修改器

	<Template modifiers="stripHtml|truncate:500" n:component>
    		Content with dynamic parameter or with macros <Template n:component />
    </Template>

与nette相同

{include __DIR__ . '/component-dir/template.latte' _content => $foo|stripHtml|truncate:500}