PHPackages                             ujpef/latte-view - 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. ujpef/latte-view

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

ujpef/latte-view
================

Latte Slim wrapper

0.0.4(7y ago)88151[1 issues](https://github.com/ujpef/latte-view/issues)MITPHP

Since Aug 19Pushed 2y ago2 watchersCompare

[ Source](https://github.com/ujpef/latte-view)[ Packagist](https://packagist.org/packages/ujpef/latte-view)[ RSS](/packages/ujpef-latte-view/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (2)Versions (5)Used By (0)

latte-view
==========

[](#latte-view)

[Latte templating engine](https://github.com/nette/latte) wrapper for [Slim microframework](https://www.slimframework.com/).

You can use this small library to integrate Latte templates into a project based on Slim framework.

This project was created for [course APV](https://akela.mendelu.cz/~lysek/tmwa/) on Mendel University in Brno.

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

[](#installation)

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

```
composer require ujpef/latte-view
```

Methods
-------

[](#methods)

### \_\_construct(Latte\\Engine $latte, $pathToTemplates)

[](#__constructlatteengine-latte-pathtotemplates)

Create an instance of Latte wrapper. Pass instance of configured Latte engine. You should configure Latte engine before you pass it to the wrapper: set up templates path and set up cache folder for templates.

```
$engine = new \Latte\Engine\Engine();
$engine->setLoader(new \Latte\Loaders\FileLoader(__DIR__ . '/../templates/'));
$engine->setTempDirectory(__DIR__ . '/../cache');

$latteView = new \Ujpef\LatteView\LatteView($engine);
```

### addParam($name, $param)

[](#addparamname-param)

Make template variable called `$name` with `$param` value.

### addParams(array $params)

[](#addparamsarray-params)

Pass multiple values into a template. The `$params` array must be associative.

### render(Response $response, $name, array $params = \[\])

[](#renderresponse-response-name-array-params--)

Render a template given by `$name` with set of template variables given by `$params` associative array and create new Response object.

Returns new instance of Response object which can be returned from route or middleware.

### addFilter($title, callable $callback)

[](#addfiltertitle-callable-callback)

Add a custom Latte filter - `{$variable|customFilter}`.

### addMacro($name, callable $callback)

[](#addmacroname-callable-callback)

Add a custom Latte macro - `{customMacro param}`.

Integration with Slim framework
-------------------------------

[](#integration-with-slim-framework)

Define a dependency for Slim framework (change templates source folder and cache directory location if needed):

```
use Latte\Engine;
use Latte\Loaders\FileLoader;
use Ujpef\LatteView;

$container['view'] = function ($container) use ($settings) {
    $engine = new Engine();
    $engine->setLoader(new FileLoader(__DIR__ . '/../templates/'));
    $engine->setTempDirectory(__DIR__ . '/../cache');

    $latteView = new LatteView($engine);
    return $latteView;
};
```

To return result of Latte template rendering call the `render()` method.

```
$app->get('/[{name}]', function (Request $request, Response $response, $args) {
    $tplVars = [
        'variable' => 123
    ];
    return $this->view->render($response, 'index.latte', $tplVars);
})->setName('index');
```

In template use:

```
>

        test template

        contents of variable: {$variable}

```

Using named routes
------------------

[](#using-named-routes)

To use Slim's build in [router](https://www.slimframework.com/docs/objects/router.html) in a Latte macro like this `{link routeName}` add following lines into dependency definition:

```
use Latte\Engine;
use Latte\MacroNode;
use Latte\PhpWriter;
use Latte\Loaders\FileLoader;
use Ujpef\LatteView;

$container['view'] = function ($container) use ($settings) {
    $engine = new Engine();
    $engine->setLoader(new FileLoader(__DIR__ . '/../templates/'));
    $engine->setTempDirectory(__DIR__ . '/../cache');

    $latteView = new LatteView($engine);
    $latteView->addParam('router', $container->router);
    $latteView->addMacro('link', function (MacroNode $node, PhpWriter $writer) {
        if (strpos($node->args, ' ') !== false) {
            return $writer->write("echo \$router->pathFor(%node.word, %node.args);");
        } else {
            return $writer->write("echo \$router->pathFor(%node.word);");
        }
    });
    return $latteView;
};
```

Remember to set names for your routes:

```
$app->get('/test', function (Request $request, Response $response, $args) {
    //route implementation
})->setName('routeName');
```

This also works with route placeholders:

```
$app->get('/test/{something}', function (Request $request, Response $response, $args) {
    //route implementation
})->setName('routeName');
```

In template use:

```
link
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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

Every ~187 days

Total

4

Last Release

2674d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4319320?v=4)[Ondrej Popelka](/maintainers/odinuv)[@odinuv](https://github.com/odinuv)

---

Top Contributors

[![odinuv](https://avatars.githubusercontent.com/u/4319320?v=4)](https://github.com/odinuv "odinuv (4 commits)")[![millken](https://avatars.githubusercontent.com/u/176581?v=4)](https://github.com/millken "millken (1 commits)")[![Wruczek](https://avatars.githubusercontent.com/u/7156344?v=4)](https://github.com/Wruczek "Wruczek (1 commits)")

### Embed Badge

![Health badge](/badges/ujpef-latte-view/health.svg)

```
[![Health](https://phpackages.com/badges/ujpef-latte-view/health.svg)](https://phpackages.com/packages/ujpef-latte-view)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k532.1M2.5k](/packages/aws-aws-sdk-php)[symfony/symfony

The Symfony PHP framework

31.4k86.9M2.2k](/packages/symfony-symfony)[moonshine/moonshine

Laravel administration panel

1.3k239.9k76](/packages/moonshine-moonshine)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k496.1k33](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35729.6k2](/packages/telnyx-telnyx-php)

PHPackages © 2026

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