berry/html
Build HTML templates directly in PHP with a fluent, type-safe element builder. Compose tags, attributes, classes, and children, then render to string. Great for minimal templating and dynamic UI patterns (e.g., HTMX) without context switching.
Pros:
div()->attr()->child()) aligns with modern PHP practices, reducing boilerplate.hx-post, hx-swap) simplifies interactive UIs without JavaScript frameworks, aligning with Laravel’s growing HTMX adoption (e.g., Livewire under the hood).counterButton() and layout() enable reusable, testable components—similar to Laravel’s view components but without the abstraction layer.Cons:
@cache), this package renders HTML on every request, which could impact performance in high-traffic apps.View facade or service provider system.Illuminate\Http\Request for handling partial responses (as shown in the example).@inject, @component, @stack).BerryHtmlGenerator facade).View facade as a fallback for complex layouts.berry/symfony)?@stack/@section is harder to replicate.// Before (Blade)
// <x-mail.template>...</x-mail.template>
// After (Berry)
function emailTemplate(): Element { ... }
$app->singleton(Button::class, fn() => new class {
public function render(int $value): Element { ... }
});
.blade.php to Berry functions.public function handle(Request $request, Closure $next) {
if ($request->expectsJson() && $request->has('berry')) {
return response($this->berryRenderer->render($request->berry));
}
return $next($request);
}
Cache::remember("berry_{$key}", now()->addHours(1), fn() => $element->toString());
function layout(Element $content): Element {
return html()->child(
link()->rel('stylesheet')->href(mix('css/app.css'))
);
}
htmx.php config (if using berry/htmx package) for global settings.| Step | Priority | Effort | Dependencies |
|---|---|---|---|
Set up Berry in composer.json |
Low | Low | None |
| Create wrapper service for Laravel | Medium | Medium | Berry package |
| Migrate email templates | High | Low | Berry wrapper |
| Replace Blade components with Berry | Medium | Medium | Berry wrapper, HTMX (optional) |
| Integrate HTMX for dynamic routes | High | High | berry/htmx package |
| Implement caching for Berry responses | Low | Medium | Laravel Cache |
| Full Blade replacement (optional) | Low | High | Custom view resolver |
@dump), Berry lacks native debugging helpers.try-catch in route callbacks).berry/html and related packages.berry/symfony as reference).How can I help you explore Laravel packages today?