Search by

crystoline / xpsr-view-latte

crystoline

Latte views for XPSR applications: context-aware escaping templates in place of Twig

Package info

github.com/crystoline/xpsr-view-latte

Homepage

pkg:composer/crystoline/xpsr-view-latte

Statistics

Installs: 3

Dependents: 0

Suggesters: 1

Stars: 0

Open Issues: 0

v0.5.0 2026-10-30 11:06 UTC

This package is auto-updated.

Last update: 2026-10-30 11:16:40 UTC


README

Latte views for XPSR applications, in place of Twig. Latte escapes each value for where it is printed: HTML text, an attribute, JavaScript, CSS, or a URL.

composer require crystoline/xpsr-view-latte
// config/app.php
'view_engine' => env('VIEW_ENGINE', 'latte'),
'view_cache_dir' => dirname(__DIR__) . '/var/cache/views',

views/home/index.latte is the view home.index:

{layout '../layouts/main.latte'}

{block content}
    <h1>Hello, {$user->name}</h1>
    {if can('update', $task)}
        <form method="post" action="/tasks/{$task->id}">
            {csrf_field()}
            <input name="title">
        </form>
    {/if}
{/block}

The template functions are called by name; csrf_field() prints its HTML as it is.

Compiled templates go to app.view_cache_dir; without one, each request compiles them again. A changed template is compiled again even with app.debug off. Latte compares each template's content, which costs about 0.2 ms for a page of three templates. To skip the check, call engine()->setAutoRefresh(false) from a service registry's boot(), and run php xpsr view:clear on every deploy. LatteViewHandler::engine() returns the Latte Engine, for filters, extensions, and other settings.

Requires PHP 8.4+.