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

Html Laravel Package

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.

View on GitHub
Deep Wiki
Context7

No more context-switching, just build your HTML templates in PHP.

Frequently asked questions about Html
Can I use berry/html to replace Blade templates in Laravel for dynamic UI components?
Yes, berry/html is ideal for dynamic components like HTMX-driven UIs, emails, or API responses. You can mix it with Blade by using it for specific sections (e.g., reusable buttons, cards) while keeping complex layouts in Blade. The fluent API reduces boilerplate compared to Blade’s syntax.
How do I install and set up berry/html in a Laravel project?
Install via Composer: `composer require berry/html`. There’s no Laravel-specific setup—just import the package and use its fluent methods (e.g., `div()->attr()->child()`) directly in your PHP files. For Laravel integration, wrap it in a service class or facade to leverage the container if needed.
Does berry/html support HTMX attributes like hx-post or hx-swap natively?
Yes, berry/html has built-in support for HTMX attributes. You can chain them directly, like `button()->attr('hx-post', '/update')->attr('hx-swap', 'outerHTML')`. This makes it a great choice for HTMX-powered Laravel apps without extra JavaScript frameworks.
Will berry/html work with Laravel 10+ and PHP 8.3+?
berry/html requires PHP 8.3+, which aligns with Laravel 10+. It’s fully compatible with modern Laravel versions, including Laravel 11. For older Laravel projects (pre-10), you’ll need to upgrade PHP first or explore alternatives like Twig or Blade.
How do I test HTML components built with berry/html in Laravel?
Test components by rendering them to strings and asserting the output. For example, use PestPHP to verify `counterButton(1)->toString()` matches expected HTML. Since components are plain PHP functions, they’re easy to unit test without Laravel’s testing helpers.
Is berry/html suitable for high-traffic Laravel applications?
berry/html renders HTML on every request, which may impact performance in high-traffic apps. Mitigate this by caching responses with Laravel’s HTTP cache middleware or using a wrapper to pre-render static components. For dynamic content, consider partial caching.
Can I use berry/html for server-side rendered emails in Laravel?
Absolutely. berry/html is perfect for dynamic emails—build email templates as PHP functions, compose reusable elements, and render them to strings. It avoids Blade’s complexity for simple emails while keeping markup close to your logic.
Are there alternatives to berry/html for PHP-based HTML generation in Laravel?
Alternatives include Blade (Laravel’s default), Twig (flexible but heavier), or PHP’s native DOMDocument. berry/html stands out for its fluent API, HTMX-first design, and PHP-native approach, making it lighter than Blade/Twig for dynamic components.
How do I integrate berry/html with Laravel’s service container?
berry/html doesn’t bind to Laravel’s container by default. Create a service class (e.g., `BerryHtmlGenerator`) that wraps berry/html methods, then register it in `AppServiceProvider`. This lets you inject components into controllers or use them via Laravel’s facade pattern.
Does berry/html support CSS/JS asset management like Laravel Mix or Vite?
No, berry/html focuses on HTML generation and doesn’t include asset pipelines. For CSS/JS, use Laravel Mix or Vite as usual. berry/html works alongside these tools—just generate HTML strings and include assets via standard `<link>` or `<script>` tags.
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