yiisoft/html
yiisoft/html is a lightweight PHP HTML builder for generating safe, well-formed markup. Create tags, attributes, forms, and input elements with fluent helpers, automatic escaping, and convenient utilities—ideal for Yii and any PHP project needing clean HTML generation.
yiisoft/html package excels in a component-driven architecture (e.g., Blade templates, Livewire, or Inertia.js) where reusable HTML fragments (buttons, forms, modals) are critical. It aligns well with Laravel’s service container and dependency injection patterns, enabling clean abstraction of HTML generation logic.yiisoft/yii), this package integrates natively, reducing friction. For pure Laravel, it requires minimal adaptation.@html) or a helper class, but lacks native Blade integration (unlike Laravel’s built-in Html facade). Requires manual setup (e.g., aliasing the class).// Traditional Laravel
<button>{{ __('Submit') }}</button>
// yiisoft/html
Html::tag('button', __('Submit'), ['class' => 'btn-primary']);
collective/html)?
assertHtml()).Html::tag()).Html::beginForm().// config/app.php
'aliases' => [
'Html' => Yiisoft\Html\Html::class,
];
// app/Facades/HtmlFacade.php
public static function tag($type, $content = '', array $options = []) {
return app(Yiisoft\Html\Html::class)->tag($type, $content, $options);
}
// app/Providers/BladeServiceProvider.php
Blade::directive('html', function ($expression) {
return "<?php echo app(\\Yiisoft\\Html\\Html::class)->{$expression}; ?>";
});
Usage: @html('tag("button", "Click", ["class" => "btn"])).Stringable).| Step | Priority | Effort | Dependencies |
|---|---|---|---|
| Evaluate pilot component | High | Low | None |
| Register service provider | Medium | Low | Laravel container |
| Create facade | Medium | Medium | Service provider |
| Blade directive | Low | Medium | Blade integration |
| Documentation | Low | High | Team training |
dd(Html::tag(...)) to inspect output.yiisoft/html patterns.| Risk | Mitigation Strategy | Detection Method |
|---|---|---|
| HTML Injection | Use Html::encode() for dynamic content. |
Static analysis (PHPStan). |
| Blade Directive Errors | Validate syntax in tests. | php artisan blade:compile. |
| Deprecation (Yii → Laravel) | Fork or wrap in a Laravel-specific layer. | Monitor package updates. |
| Performance Bottleneck | Profile with Xdebug; avoid nested tags. | Laravel Debugbar. |
yiisoft/html vs. native Blade.Html::activeTextInput() vs. Blade).yiisoft/html.config('html.use_yiisoft') to toggle.How can I help you explore Laravel packages today?