Download the PHP package akawalko/latte-template-renderer without Composer
On this page you can find all versions of the php package akawalko/latte-template-renderer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download akawalko/latte-template-renderer
More information about akawalko/latte-template-renderer
Files in akawalko/latte-template-renderer
Package latte-template-renderer
Short Description Interface implementation for a class that renders tests/templates for string and PSR-7 response objects using Latte engine - a Next-Generation Templating System for PHP.
License MIT
Informations about the package latte-template-renderer
latte-template-renderer
Interface implementation for a class that renders templates for string and PSR-7 response objects using Latte engine - a Next-Generation Templating System for PHP.
Installation
You can download this library using Composer:
Require php: >=8.0
Setup
Example integration using the PHP-DI container.
Methods
__get(string $name);
Get template variable. Return mixed value.
__set(string $name, $value): void;
Set template variable.
__isset(string $name): bool;
Determine if a variable is declared and is different than null.
__unset(string $name): void;
Unset a given variable
getVar(string $name);
Get template variable. Return mixed value.
setVar(string $name, $value): self;
Set template variable.
getVars(): array;
Get template variables.
setVars($data = []): self;
Set template variables from associative arrays or object. When an object is given, this method will work in a way similar to the spread operator known from handling arrays. That is, each object property will be assigned to the template as a standalone, e.g. Let's consider this example,
In the template, however, the data will be available without using a prefix in the form of an object
For this to work, the given object must meet 1 of 3 conditions:
- implement JsonSerializable interface
- implement toArray() method
- simply be an object of the stdClass class
However, there is a caveat when your class implements the JsonSerializable interface. Namely, when the jsonSerialize() method returns a scalar instead of an array, its value will be assigned to a key called object_single_var. Subsequent assignments will overwrite this value. At this moment it is not possible to set a key name for the returned scalar. This may change in the future depending on how useful this feature will be.
If you are not sure what data the objects will return after executing the jsonSerialize method, it will be better to assign them using setVar(string $name, $value) method.
renderToString(string $templatePath, $data = []): string;
Render the template to string with given data.
renderToResponse(ResponseInterface $response, string $templatePath, $data = []): ResponseInterface;
Render the template to PSR compliant Response class with given data.
render(...$arguments);
A shortcut method that executes renderToString() or renderToResponse() based on the arguments passed. Return ResponseInterface or string.
All versions of latte-template-renderer with dependencies
ext-json Version *
ext-tokenizer Version *
latte/latte Version ^3.0
akawalko/template-renderer-interface Version ^1.0