- How do I integrate yiisoft/html into a Laravel project?
- Install via Composer with `composer require yiisoft/html`. Register the service provider in `config/app.php` or use facades like `Html::tag()` directly in Blade/Livewire. For Blade directives, create a custom helper or facade to bridge the package’s methods.
- Does yiisoft/html support Laravel 10+ and PHP 8.1+?
- Yes, the package is fully compatible with Laravel 10+ and PHP 8.1+. It enforces stricter type handling (e.g., `int`, `float`, `null` for tag content) and may require updates to dynamic HTML logic using older PHP versions.
- What’s the breaking change with `$options` renamed to `$attributes`?
- Methods like `addCssClass()` now use `$attributes` instead of `$options`. Update any custom helpers, Blade directives, or service providers using these methods. This improves clarity but requires code changes.
- Can I use yiisoft/html with Livewire or Inertia.js?
- Yes, the package works well with Livewire for dynamic components (e.g., `CheckboxList`, `RadioList`) and Inertia.js for server-rendered HTML. Stricter validation (e.g., required `CheckboxItem` properties) enhances robustness in these use cases.
- How does yiisoft/html handle XSS prevention?
- All tag content is auto-encoded by default. Use the `NoEncode` class for raw content (e.g., JavaScript). This aligns with Laravel’s security best practices for server-side HTML generation.
- Are there alternatives to yiisoft/html for Laravel?
- For Blade templates, consider Laravel’s built-in `Html::tag()` or packages like `spatie/html`. For component-based apps, `livewire/ui` or `filament/support` offer integrated solutions. yiisoft/html stands out for its widget support (e.g., `ButtonGroup`) and Yii’s legacy.
- Will yiisoft/html work with Alpine.js or Vue/React?
- The package is PHP-focused and lacks native JS framework integration. For Vue/React, use inline Blade templates or Laravel Mix/Vite for static HTML. Dynamic components should use Laravel’s frontend presets (e.g., `laravel-mix` with `vue-loader`).
- How do I handle empty IDs in tags after the LogicException change?
- Validate IDs before passing them to `Tag::id()`. For example, use `Html::tag('div', '', ['id' => $id ?? 'default-id'])` or throw a custom exception if IDs are critical. This change prevents runtime errors in production.
- Does yiisoft/html support deterministic attribute sorting?
- No, the package removed attribute sorting (Chg #234). If your project relies on consistent HTML output (e.g., for minification or testing), implement custom sorting logic or use a post-processing tool like `htmlmin`.
- How can I test yiisoft/html in a Laravel project?
- Test by generating tags in unit tests (e.g., `Html::tag('div', 'test')`) and asserting output with PHPUnit. Mock `Html` facades or use `partial()` in Blade tests. Validate edge cases like encoding, empty IDs, and widget rendering (e.g., `CheckboxList`).