Componette

Componette

WebChemistry

WebChemistry / component-macro 2.0

Replacement of include, import from nette with more beautiful and shorter version.

download-cloud-line composer require webchemistry/component-macro

Component-Macro

Replacement of include, import from nette with more beautiful and shorter version.

Build Status

Installation

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

Usage single file

	<Template n:component />

~ Same in nette:

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

Renders content from component-dir/template.latte

Usage single file, multiple blocks

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

Same in nette:

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

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

template.latte

{define first}
    ...
{/define}

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

Usage file from other directory

    <TemplateFirst n:component />

Same in nette:

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

template/first.latte:

...

Custom parameters

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

Same in nette:

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

template.latte

	{$foo}

Content

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

Same in 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}

Modifiers

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

Same in nette:

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

Badges

guide-fill

Dependencies

php (>= 7.1)
latte/latte (>=2.4.3)
Componette Componette felix@nette.org