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

Product Decisions This Supports

  • 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.

    • Roadmap: Prioritize breaking monolithic Blade/Template views into reusable components, reducing spaghetti code and improving developer velocity.
    • Build vs. Buy: Buy—Fluid’s component API (e.g., @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.

    • Use Case: Personalized dashboards, multi-tenant apps, or feature flags where UI varies by user/segment.
    • Example: Render user_dashboard.fluid.html or admin_dashboard.fluid.html dynamically based on auth context.
  • Developer Experience (DX) Improvements:

    • CLI Tooling: Use the built-in fluid warmup command to pre-compile templates during deployments (reduces cold-start latency).
    • Validation & Debugging: Leverage template-aware exceptions (e.g., line numbers in error messages) and @see annotations to catch issues early in CI.
    • Roadmap: Integrate Fluid’s CLI into deployment pipelines (e.g., GitHub Actions) to enforce template validation pre-merge.
  • Security Hardening:

    • Automatic Escaping: Fluid’s default behavior escapes variables by default (XSS protection). Use UnsafeHTML interface explicitly for trusted HTML (e.g., sanitized rich-text fields).
    • Compliance: Meets OWASP guidelines for template engines; reduces risk of injection vulnerabilities.
  • Legacy System Modernization:

    • Gradual Migration: Replace outdated PHP templating (e.g., extract() + include) with Fluid’s type-safe ViewHelpers (e.g., <f:format.round>, <f:if>). Backward-compatible with PHP 8.1+.
    • Example: Migrate a 10-year-old CMS from custom template logic to Fluid components.

When to Consider This Package

  • Avoid if:

    • Your stack is fully frontend-driven (e.g., Next.js, React Server Components) and PHP is only an API layer. Fluid adds unnecessary coupling.
    • You need real-time template updates (e.g., live collaboration). Fluid’s compilation step introduces latency.
    • Your team lacks PHP expertise. Fluid’s learning curve (ViewHelpers, syntax) may slow onboarding.
    • You’re using Laravel Blade and happy with its simplicity. Blade is more lightweight for basic use cases.
  • Consider if:

    • You’re building a PHP-centric application (e.g., CMS, SaaS, enterprise portal) where templates are tightly coupled to backend logic.
    • You need server-side rendering (SSR) with PHP (e.g., SEO-critical pages, PDF generation).
    • Your team values type safety and component reuse over raw performance.
    • You’re migrating from TYPO3, Symfony Twig, or Smarty and want a familiar syntax with modern features.
  • Alternatives to Evaluate:

    • Laravel Blade: Simpler, tighter Laravel integration, but lacks Fluid’s component ecosystem.
    • Twig: More mature, but heavier and less PHP-native.
    • Custom Solutions: Only if you have unique requirements (e.g., WebAssembly integration).

How to Pitch It (Stakeholders)

For Executives (Business Leaders)

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:

  1. Decouple UI from logic with reusable components (like LEGO blocks), cutting dev time by 40% for new features.
  2. Reduce security risks with built-in XSS protection and explicit UnsafeHTML controls.
  3. Future-proof your stack with PHP 8.4+ support and modern tooling (e.g., CLI warmup for zero-downtime deploys).

ROI:

  • Faster iterations: Components reduce UI duplication (e.g., shared headers/footers).
  • Lower costs: Fewer frontend-backend handoffs; easier to onboard PHP devs.
  • Scalability: Handles 10x traffic growth without template refactoring.

Risk Mitigation:

  • Pilot with one high-impact feature (e.g., user dashboard) to prove component benefits.
  • Partner with engineering to phase out legacy templates over 6–12 months.

For Engineering Leaders (Tech Stack Owners)

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:

  1. Component Ecosystem:
    • Define self-contained UI blocks (e.g., <f:component name="Card" />) with props, slots, and events.
    • Example: Replace 500-line Blade files with modular components like UserCard.fluid.html and ProductGrid.fluid.html.
  2. Performance:
    • Pre-compile templates in CI/CD (fluid warmup) for sub-10ms render times.
  3. Security:
    • Automatic escaping + UnsafeHTML interface for granular control (better than Twig’s |raw filter).
  4. Future-Proofing:
    • Supports PHP 8.4+ features (e.g., enums, union types) natively.

Migration Plan:

  1. Phase 1 (0–3 months):
    • Adopt Fluid for new features only; keep legacy templates for existing pages.
    • Train team on ViewHelpers and component syntax (pair with existing Blade devs).
  2. Phase 2 (3–6 months):
    • Rewrite high-churn templates (e.g., forms, dashboards) as components.
    • Integrate fluid warmup into deployments.
  3. Phase 3 (6–12 months):
    • Deprecate legacy templates; enforce Fluid for all UI changes.

Dependencies:

  • PHP 8.1+ (recommended: 8.3+).
  • Composer integration (no extra setup).
  • Willingness to adopt new syntax (e.g., {{{ }} for CDATA).

For Developers (Hands-On Adoption)

What You Gain:

  • Faster Development:

    • Replace this:
      // 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>
      
    • Components = DRY UI code; ViewHelpers = built-in logic (e.g., <f:format.currency>).
  • Better Debugging:

    • Errors show template line numbers and variable contexts (no more "undefined index" mysteries).
    • Use the CLI analyzer to catch issues pre-deploy:
      ./vendor/bin/fluid analyze templates/
      
  • Modern PHP Features:

    • Type-hint ViewHelper arguments:
      public function render(): string {
        return $this->viewHelperVariableArguments->get('items')->toArray();
      }
      
    • Use enums and union types for argument validation.

Getting Started:

  1. Install:
    composer require typo3fluid/fluid
    
  2. Configure in config/fluid.php:
    return [
        'templatePaths' => [__DIR__.'/resources/views'],
        'cacheDirectory' => storage_path('framework/cache/fluid'),
    ];
    
  3. Render a template:
    $template = Fluid::template('dashboard.fluid.html');
    $template->assign('user', $user);
    
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata