crystoline / xpsr-view-latte
Latte views for XPSR applications: context-aware escaping templates in place of Twig
Requires
- php: ^8.4
- crystoline/xpsr-framework: ^0.5@dev
- latte/latte: ^3.1.2
Requires (Dev)
- nyholm/psr7: ^1.8.2
- phpunit/phpunit: ^12.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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+.