PHPackages                             akawalko/latte-template-renderer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. akawalko/latte-template-renderer

ActiveLibrary[Templating &amp; Views](/categories/templating)

akawalko/latte-template-renderer
================================

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.

v1.0.0(2y ago)05MITPHPPHP &gt;=8.0

Since Jan 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/akawalko/latte-template-renderer)[ Packagist](https://packagist.org/packages/akawalko/latte-template-renderer)[ RSS](/packages/akawalko-latte-template-renderer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

latte-template-renderer
=======================

[](#latte-template-renderer)

[Interface](https://github.com/akawalko/template-renderer-interface) implementation for a class that renders templates for string and [PSR-7](https://www.php-fig.org/psr/psr-7/) response objects using [Latte](https://github.com/nette/latte) engine - a Next-Generation Templating System for PHP.

Installation
------------

[](#installation)

You can download this library using [Composer](https://getcomposer.org/):

Require php: &gt;=8.0

```
composer require akawalko/latte-template-renderer

```

Setup
-----

[](#setup)

Example integration using the [PHP-DI](https://php-di.org/) container.

```
// app/dependencies.php
return function (ContainerBuilder $containerBuilder) {
        LatteRenderer::class => function (ContainerInterface $c) {
            $latte = new \Latte\Engine();
            $latte->setLoader(new FileLoader($c->get('templates.directory.host')));
            $latte->setTempDirectory($c->get('templates.directory.temp_directory'));
            $latte->setAutoRefresh($c->get('templates.directory.auto_refresh'));

            // If you have any additional filters or extensions, register them now.
            //$latte->addExtension(new SomekindExtension());
            //$latte->addFilter('some_filter', fn(string $s) => ...);

            return new LatteTemplateRenderer($latte);
        },
        // A convenient alias
        'template' => get(TemplateRenderer::class),
};
```

Methods
-------

[](#methods)

### \_\_get(string $name);

[](#__getstring-name)

Get template variable. Return mixed value.

### \_\_set(string $name, $value): void;

[](#__setstring-name-value-void)

Set template variable.

### \_\_isset(string $name): bool;

[](#__issetstring-name-bool)

Determine if a variable is declared and is different than null.

### \_\_unset(string $name): void;

[](#__unsetstring-name-void)

Unset a given variable

### getVar(string $name);

[](#getvarstring-name)

Get template variable. Return mixed value.

### setVar(string $name, $value): self;

[](#setvarstring-name-value-self)

Set template variable.

### getVars(): array;

[](#getvars-array)

Get template variables.

### setVars($data = \[\]): self;

[](#setvarsdata---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,

```
$obj = new \stdClass();
$obj->firstname = 'John';
$obj->lastname = 'Connor';
$obj->age = '34';

$latteRenderer->setVars($obj);
```

In the template, however, the data will be available without using a prefix in the form of an object

```
// this
{$firstname}
{$lastname}
{$age}
// instead of
{$someObjectname->firstname}
{$someObjectname->$lastname}
{$someObjectname->$age}
```

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;

[](#rendertostringstring-templatepath-data---string)

Render the template to string with given data.

### renderToResponse(ResponseInterface $response, string $templatePath, $data = \[\]): ResponseInterface;

[](#rendertoresponseresponseinterface-response-string-templatepath-data---responseinterface)

Render the template to PSR compliant Response class with given data.

### render(...$arguments);

[](#renderarguments)

A shortcut method that executes renderToString() or renderToResponse() based on the arguments passed. Return ResponseInterface or string.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

852d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8fca236fe992bd3222344ed9cb9296e25b3c3753dc18054d2175a5926c6be9a1?d=identicon)[akawalko](/maintainers/akawalko)

---

Top Contributors

[![akawalko](https://avatars.githubusercontent.com/u/7594428?v=4)](https://github.com/akawalko "akawalko (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/akawalko-latte-template-renderer/health.svg)

```
[![Health](https://phpackages.com/badges/akawalko-latte-template-renderer/health.svg)](https://phpackages.com/packages/akawalko-latte-template-renderer)
```

###  Alternatives

[contributte/latte

Extra contrib to nette/latte

111.5M2](/packages/contributte-latte)[nepada/form-renderer

Latte template based form renderer for Nette forms with full support for Bootstrap 3, 4 &amp; 5.

11251.0k](/packages/nepada-form-renderer)[nextras/forms-rendering

Rendering helpers for Nette Framework Forms.

1698.4k2](/packages/nextras-forms-rendering)[webrouse/n-asset-macro

Asset macro for Latte and Nette Framework useful for assets cache busting (with gulp, webpack, etc.)

1264.4k1](/packages/webrouse-n-asset-macro)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
