Na navigaci | Klávesové zkratky

Add the `{texy}` Tag to Latte

As of version 3.1.6, the Texy library adds support for Latte 3 in the form of the {texy} tag. What can it do and how do you deploy it?

The {texy} tag represents an easy way to write directly in Texy syntax in Latte templates:

{texy}
You Already Know the Syntax
----------

No kidding, you know Latte syntax already. **It is the same as PHP syntax.**
{/texy}

Simply install the extension in Latte and pass it a Texy object configured as needed:

$texy = new Texy\Texy;
$latte = new Latte\Engine;
$latte->addExtension(new Texy\Bridges\Latte\TexyExtension($texy));

If there is static text between the {texy}...{/texy} tags, it is translated using Texy during the template compilation and the result is stored in it. If the content is dynamic (i.e., there are Latte tags inside), the processing using Texy is performed each time the template is rendered.

If it is desirable to disable Latte tags inside, it can be done like this:

{texy syntax: off} ... {/texy}

In addition to the Texy object, a custom function can also be passed to the extension, thus allowing parameters to be passed from the template. For instance, we might want to pass the parameters locale and heading:

$processor = function (string $text, int $heading = 1, string $locale = 'cs'): string {
	$texy = new Texy\Texy;
	$texy->headingModule->top = $heading;
	$texy->typographyModule->locale = $locale;
	return $texy->process($text);
};

$latte = new Latte\Engine;
$latte->addExtension(new Texy\Bridges\Latte\TexyExtension($processor));

Parameters in the template are passed like this:

{texy locale: en, heading: 3}
...
{/texy}

If you want to format text stored in a variable using Texy, you can use a filter:

{$description|texy}

Leave a comment

Text of the comment
Contact

(kvůli gravataru)



*kurzíva* **tučné** "odkaz":http://example.com /--php phpkod(); \--

phpFashion © 2004, 2024 David Grudl | o blogu

Ukázky zdrojových kódů smíte používat s uvedením autora a URL tohoto webu bez dalších omezení.