Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Latte Laravel Package

latte/latte

Latte is a safe, intuitive PHP templating engine with automatic context-aware escaping, template inheritance, blocks, filters, and sandbox mode. It catches many errors at compile time, produces readable compiled PHP, and works with Nette or standalone projects. It offers developer-friendly syntax.

View on GitHub
Deep Wiki
Context7

Latte is a secure and intuitive PHP templating engine designed for everyday use. It compiles templates into optimized PHP, offers context-aware automatic escaping, and provides clear error reporting with source maps. Use it standalone or with frameworks like Nette.

  • Intuitive syntax close to PHP
  • Automatic context-aware escaping
  • Template inheritance, blocks, and n:attributes
  • Compiled to fast, optimized PHP
  • Excellent debugging and error messages
Frequently asked questions about Latte
Can I use Latte as a direct replacement for Laravel Blade in my existing project?
Latte can replace Blade but requires custom wrappers for Laravel-specific directives like `@foreach`, `@stack`, or `@inject`. You’ll need to map these to Latte’s syntax (e.g., `{foreach}`, `{layout}`) and rebuild any Blade-specific logic. Start with a hybrid approach by testing critical views first.
How does Latte’s security model compare to Blade’s escaping in Laravel?
Latte enforces **context-sensitive escaping by default** (HTML, JS, ATTR, TEXT), unlike Blade’s opt-in `|e` filter. It auto-escapes dynamic content and handles HTML attributes smartly (e.g., `data-*` attributes are JSON-encoded). This reduces XSS risks without manual effort, making it stricter than Blade’s default behavior.
Will Latte work with Laravel’s view caching (e.g., `php artisan view:clear`)?
Latte’s compiled templates are stored in `storage/latte-cache/`, separate from Laravel’s `bootstrap/cache/`. To integrate, hook into Laravel’s `ViewCompiled` event or create a custom Artisan command to purge Latte’s cache when running `view:clear`. Alternatively, use Laravel’s filesystem cache adapter for Latte.
Does Latte support Laravel’s `@stack` directive for layout sections?
Latte doesn’t have a direct `@stack` equivalent, but you can replicate it using `{block}` with a custom extension or macro. For example, define a `stack` macro in Latte to manage section content dynamically. This requires writing a small wrapper class to handle section stacking logic.
How do I handle Laravel’s CSRF tokens or `@error` directives in Latte templates?
Latte lacks built-in CSRF or validation helpers, but you can create **global functions** or **macros** to wrap Laravel’s `csrf_token()` or `old()` methods. For example, add a macro like `{csrf}` that outputs Laravel’s CSRF token. Similarly, use `{error}` macros to display validation errors with Latte’s `{if}` syntax.
What’s the performance impact of using Latte vs. Blade in Laravel?
Latte adds **~10–20% overhead** during template compilation compared to Blade due to its stricter parsing and security checks. However, runtime performance is nearly identical once compiled. Benchmark with your specific workload, as Latte’s optimizations (e.g., `{case}` → `===` comparisons) may offset this in complex templates.
Can I use Latte with Laravel’s asset management (Mix/Vite) and localization features?
Latte supports asset paths via `@assets` directives (with extensions) but lacks native Mix/Vite integration. For localization, Latte has built-in `trans` filters, but you’ll need to bridge Laravel’s `__()` function via a macro or helper. Consider creating a Latte extension for Mix/Vite asset URLs.
Are there any Laravel-specific packages or tools that support Latte?
Currently, **no official Laravel packages** support Latte, but you can adapt existing tools like `laravelcollective/html` by forking them or writing Latte-specific wrappers. For IDE tooling, Latte’s **Range spans** enable debugging in PHPStorm/VSCode, but Blade-specific tools (e.g., `blade.php`) won’t work without customization.
How do I migrate from Blade to Latte in an existing Laravel project?
Start by **converting templates incrementally**: replace `@extends`, `@section` with `{extends}`, `{block}`, and map `@foreach` to `{foreach}`. Use a **custom macro system** for Laravel-specific features (e.g., `@inject`). Test critical paths first, then update routes, controllers, and service providers to handle Latte’s stateless engine. Consider a migration script to auto-convert Blade syntax.
What Laravel versions and PHP versions does Latte support?
Latte 3.x requires **PHP 8.2+** (for strict types and new syntax like the pipe operator). It works with **Laravel 9+**, but you’ll need to handle service container integration manually (e.g., via a `LatteServiceProvider`). For older Laravel versions, use Latte 2.x, but note it lacks PHP 8.5+ features and may have compatibility gaps.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings