- Can I use TYPO3Fluid in Laravel without TYPO3 CMS dependencies?
- Yes, the standalone package `typo3fluid/fluid` is fully decoupled from TYPO3 CMS. It includes only the templating engine, ViewHelpers, and core rendering logic, making it lightweight and Laravel-ready. You’ll need to configure it via a Laravel Service Provider to integrate with Laravel’s view system.
- How do I integrate Fluid templates into Laravel’s view system?
- Use a Laravel Service Provider to register Fluid’s compiler and bind it to Laravel’s view resolver. This allows you to render `.fluid.html` files via `return view('fluid::template')` or embed them in Blade files using `@include('fluid::partial')`. The package provides a `TemplateViewHelper` to bridge Fluid’s context with Laravel’s data.
- Does Fluid support Laravel’s Livewire or Inertia for reactive UIs?
- Yes, Fluid components can be mapped to Livewire/Inertia props using custom ViewHelpers or directives like `@mount` and `@bind`. For example, you can pass Livewire properties to Fluid components via `this->props` and bind them to Fluid’s `{{variable}}` syntax. This enables dynamic UIs without JavaScript-heavy solutions.
- What Laravel versions and PHP versions does Fluid v5 support?
- Fluid v5 requires **PHP 8.1+** and is compatible with **Laravel 9+**. For older Laravel versions (e.g., 8.x), use Fluid v4.6, which supports PHP 7.4+. Always pin the exact version in `composer.json` to avoid dependency conflicts, especially with Symfony polyfills.
- How does Fluid’s performance compare to Blade in Laravel?
- Fluid templates are compiled to PHP at runtime (unless pre-compiled), which adds a slight overhead compared to Blade’s native parsing. However, Laravel’s OPcache mitigates this. Benchmark with tools like `laravel-debugbar` to measure compilation latency, especially in high-traffic apps. Pre-compiling templates during deployment can further optimize performance.
- Can I migrate from Blade to Fluid incrementally in Laravel?
- Yes, Fluid and Blade can coexist. Start by using Fluid for new features or complex components (e.g., admin panels) while keeping Blade for legacy views. Use `@include('fluid::partial')` in Blade files to embed Fluid templates gradually. Tools like `artisan view:clear` help manage cache inconsistencies during migration.
- How do I handle XSS risks with Fluid’s UnsafeHTML ViewHelper?
- Fluid’s `UnsafeHTML` interface (v4.6+) allows controlled HTML injection by explicitly marking content as trusted. For example, `<f:format.html>{userInput}</f:format.html>` escapes by default, while `<f:format.raw>{userInput}</f:format.raw>` bypasses escaping. Always validate input before using `UnsafeHTML` to mitigate XSS risks.
- Are there IDE tools or autocompletion for Fluid ViewHelpers in Laravel?
- Fluid lacks native Laravel IDE support, but you can use PHPStorm’s **Fluid plugin** or generate PHPDoc stubs for ViewHelpers. For custom ViewHelpers, annotate them with `@mixin` or `@template` tags to improve autocompletion. Alternatively, tools like **Barryvdh/Laravel-Ide-Helper** can generate stubs for Fluid’s core classes.
- How do I cache Fluid templates in Laravel for production?
- Leverage Laravel’s caching layer by configuring Fluid’s `TemplateCompiler` to use `file`, `redis`, or `database` cache drivers. Run `php artisan cache:clear` or `php artisan view:clear` to invalidate cached templates. For warmup, use Fluid’s CLI tool (`bin/fluid warmup`) or a Laravel command to pre-compile templates during deployment.
- What are the alternatives to Fluid for component-based templating in Laravel?
- Alternatives include **Blade with components** (native Laravel), **Livewire/Vue/React** for dynamic UIs, or **PHP-Twig** for a more PHP-centric templating engine. Blade is simpler for small projects, while Twig offers stricter syntax but lacks Fluid’s ViewHelper ecosystem. Fluid stands out for its **component encapsulation** and **TYPO3-proven** architecture, making it ideal for large-scale, reusable UI systems.