typo3fluid/fluid
TYPO3Fluid is a standalone PHP templating engine extracted from TYPO3 CMS. It provides secure, flexible templates with ViewHelpers, layouts, sections and partials, plus extensibility and caching, making it suitable for MVC apps and reusable component rendering.
Component-Based UI Development: Adopt a modular, reusable UI architecture by leveraging Fluid’s component system (introduced in v5.x) to build encapsulated, self-contained UI blocks (e.g., cards, modals, forms). This aligns with modern frontend frameworks like React/Vue but integrates natively with PHP backend logic.
@component, <f:render section="...">) eliminates the need to build a custom solution from scratch.Dynamic Template Rendering: Enable runtime template selection (e.g., A/B testing, user-specific layouts) using Fluid’s template fallback chain and UnsafeHTML interface for safe HTML injection.
user_dashboard.fluid.html or admin_dashboard.fluid.html dynamically based on auth context.Developer Experience (DX) Improvements:
fluid warmup command to pre-compile templates during deployments (reduces cold-start latency).@see annotations to catch issues early in CI.Security Hardening:
UnsafeHTML interface explicitly for trusted HTML (e.g., sanitized rich-text fields).Legacy System Modernization:
extract() + include) with Fluid’s type-safe ViewHelpers (e.g., <f:format.round>, <f:if>). Backward-compatible with PHP 8.1+.Avoid if:
Consider if:
Alternatives to Evaluate:
Problem: Your team spends 20–30% of dev time maintaining brittle, hard-to-scale templates. UI changes require full-stack coordination, and bugs (e.g., XSS, broken layouts) slip through QA.
Solution: Adopt Fluid to:
UnsafeHTML controls.ROI:
Risk Mitigation:
Why Fluid Over Alternatives?
| Feature | Fluid | Blade (Laravel) | Twig |
|---|---|---|---|
| Component System | ✅ First-class (@component) |
❌ (Limited) | ❌ |
| Type Safety | ✅ Strict ViewHelper args | ❌ (Loose) | ✅ (Partial) |
| PHP Integration | ✅ Native (no VM overhead) | ✅ (Tight) | ❌ (Separate) |
| DX Tooling | ✅ CLI, annotations, validation | ✅ (Basic) | ✅ (Advanced) |
| Learning Curve | Moderate (ViewHelpers) | Low | High |
Key Advantages:
<f:component name="Card" />) with props, slots, and events.UserCard.fluid.html and ProductGrid.fluid.html.fluid warmup) for sub-10ms render times.UnsafeHTML interface for granular control (better than Twig’s |raw filter).Migration Plan:
fluid warmup into deployments.Dependencies:
{{{ }} for CDATA).What You Gain:
Faster Development:
// Legacy Blade
@foreach($products as $product)
<div class="product">{{ $product->name }}</div>
@endforeach
With this:
<!-- Fluid Component -->
<f:render section="products">
<f:for each="{products}" as="product">
<div class="product">{{ product.name }}</div>
</f:for>
</f:render>
<f:format.currency>).Better Debugging:
./vendor/bin/fluid analyze templates/
Modern PHP Features:
public function render(): string {
return $this->viewHelperVariableArguments->get('items')->toArray();
}
Getting Started:
composer require typo3fluid/fluid
config/fluid.php:
return [
'templatePaths' => [__DIR__.'/resources/views'],
'cacheDirectory' => storage_path('framework/cache/fluid'),
];
$template = Fluid::template('dashboard.fluid.html');
$template->assign('user', $user);
How can I help you explore Laravel packages today?