Weave Code
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

Fluid Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Template Rendering Engine: Fluid is a mature, standalone templating engine designed for PHP, offering a declarative syntax with powerful features like ViewHelpers, sections, and partials. It aligns well with Laravel’s Blade but provides stricter type safety, component-based rendering, and annotation-driven APIs—useful for complex UI logic.
  • Separation of Concerns: Fluid’s ViewHelper system (e.g., f:format., f:if) mirrors Laravel’s directives but with stronger validation (e.g., StrictArgumentProcessor). This could replace Blade for projects requiring compile-time safety or enterprise-grade templating.
  • Standalone vs. TYPO3 Integration: While originally tied to TYPO3 CMS, the standalone version removes CMS dependencies, making it Laravel-compatible with minimal overhead.

Integration Feasibility

  • Laravel Compatibility:
    • Blade Replacement: Fluid can replace Blade for dynamic templates, components, and reusable UI blocks (e.g., {{ component('header') }}).
    • Service Provider Integration: Fluid’s Fluid class can be bootstrapped via Laravel’s service container, with template paths mapped to Laravel’s resources/views.
    • View Composers: Fluid’s @layout and @section directives can emulate Laravel’s stacked views or master layouts.
  • Performance:
    • Caching: Fluid supports template compilation (via fluid warmup) and opcode caching, comparable to Blade’s compiled views.
    • Overhead: Standalone Fluid adds ~5–10MB to vendor dependencies (vs. Blade’s ~2MB), but offers richer features (e.g., annotations, CLI analysis).

Technical Risk

  • Breaking Changes:
    • Fluid 5.x introduces strict argument validation (e.g., union types, iterable), which may require migrating custom ViewHelpers.
    • File extensions (*.fluid.html) are optional but recommended for new projects.
  • Learning Curve:
    • XML-like syntax (<f:for>) differs from Blade’s {!! !!} or @foreach.
    • ViewHelper development requires PHP classes (vs. Blade’s directives).
  • Ecosystem Gaps:
    • No native Laravel-specific integrations (e.g., Inertia.js, Livewire support).
    • No official Laravel package, requiring custom setup.

Key Questions

  1. Use Case Fit:
    • Is Fluid needed for complex UI logic (e.g., dynamic forms, component-based UIs) beyond Blade’s capabilities?
    • Would TYPO3’s enterprise features (e.g., annotations, CLI analysis) justify the integration?
  2. Migration Path:
    • How will Blade templates transition to Fluid? (Tooling like laravel-shift/fluid could help.)
    • What’s the fallback strategy for unsupported Blade features (e.g., @stack)?
  3. Performance Trade-offs:
    • Will compilation overhead (vs. Blade’s runtime parsing) impact cold starts?
    • How will cache invalidation (e.g., fluid warmup) integrate with Laravel’s cache drivers?
  4. Team Adoption:
    • Does the team have PHP templating experience? Fluid’s syntax is steeper than Blade’s.
    • Are custom ViewHelpers needed, or will built-ins suffice?

Integration Approach

Stack Fit

  • Laravel Core:
    • Service Provider: Register Fluid’s Fluid class as a view resolver alongside Blade.
    • Template Paths: Map Laravel’s resources/views to Fluid’s templateRootPath.
    • Service Container: Bind Fluid’s TemplateParser, ViewHelperResolver, etc., as Laravel services.
  • Routing:
    • Use Laravel’s route model binding to pass data to Fluid templates (e.g., return Fluid::render('page', ['user' => $user])).
  • Middleware:
    • Extend Laravel’s view middleware to support Fluid’s @layout and @section directives.

Migration Path

  1. Phase 1: Dual Support
    • Run Blade and Fluid in parallel using a custom view resolver that routes templates by file extension (e.g., *.fluid.blade.php).
    • Example:
      // app/Providers/AppServiceProvider.php
      View::addLocation(public_path('resources/views'));
      View::addExtension('fluid', function ($view) {
          return Fluid::render($view->name(), $view->data());
      });
      
  2. Phase 2: Incremental Replacement
    • Migrate static templates (e.g., about.fluid.html) first.
    • Replace Blade components (@component) with Fluid partials (<f:render partial="partial" />).
    • Use Fluid’s CLI (fluid analyze) to validate templates pre-deployment.
  3. Phase 3: Full Adoption
    • Deprecate Blade in favor of Fluid.
    • Leverage Fluid’s annotations for runtime metadata (e.g., @component, @template).

Compatibility

Feature Blade Support Fluid Support Workaround
Template Inheritance @extends @layout Map @extends to @layout
Sections @section @section Direct compatibility
Components @component <f:render> Custom ViewHelper
Directives {!! !!} {} Use {{{ }}} for raw output
Stacks @stack No Custom ViewHelper or JS
Inertia.js Yes No Proxy through Blade or JS

Sequencing

  1. Setup Fluid:
    • Install via Composer: composer require typo3fluid/fluid.
    • Configure in config/app.php:
      'view' => [
          'resolvers' => [
              FluidResolver::class,
              // BladeResolver remains for dual support
          ],
      ],
      
  2. Template Conversion:
    • Use a regex-based tool to convert Blade syntax to Fluid (e.g., @foreach<f:for>).
    • Example:
      @foreach($items as $item)
          {{ $item->name }}
      @endforeach
      
      <f:for each="{items}" as="item">
          {item.name}
      </f:for>
      
  3. ViewHelper Development:
    • Create custom ViewHelpers for missing Blade features (e.g., @stack).
    • Example:
      namespace App\ViewHelpers;
      use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
      
      class StackViewHelper extends AbstractViewHelper {
          public function render(): string {
              // Implement stack logic
          }
      }
      
  4. Testing:
    • Use Pest/Laravel to test Fluid templates alongside Blade.
    • Validate cache warmup (php artisan fluid:warmup).

Operational Impact

Maintenance

  • Dependency Updates:
    • Fluid follows semver, but major versions (e.g., 5.x) may require ViewHelper migrations.
    • Laravel’s PHP version support (8.1+) aligns with Fluid’s requirements.
  • Debugging:
    • Fluid provides detailed exceptions (e.g., line numbers, template paths), improving error tracking.
    • CLI tools (fluid analyze) help catch issues pre-deployment.
  • Documentation:
    • Fluid’s docs are TYPO3-centric; Laravel-specific guides (e.g., service provider setup) must be created.

Support

  • Community:
    • TYPO3 Slack/Discord for Fluid-specific issues.
    • Laravel forums for integration help (limited prior art).
  • Vendor Lock-in:
    • Fluid is LGPL-3.0, but custom ViewHelpers may need maintenance if Fluid evolves.
    • Forking risk is low; TYPO3’s Fluid is stable.

Scaling

  • Performance:
    • Compiled templates (via fluid warmup) reduce runtime parsing overhead.
    • Caching: Fluid’s resolver delegates optimize repeated template lookups.
    • Benchmark: Compare against Blade using laravel-debugbar or custom benchmarks.
  • Concurrency:
    • Fluid’s stateless rendering (per-request) scales well with Laravel’s queue workers.
    • Cache invalidation must sync with Laravel’s event system (e.g., View::flush()).

**Failure Modes

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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope