spatie/html-element
Generate dynamic HTML in PHP with a hyperscript-style API plus Emmet-like selectors. Build elements and attributes with a simple render helper (often wrapped as el()) to produce nested markup cleanly and programmatically, ideal for small view components.
el('card', [...]) for a UI card).@php echo el('div', [...]) @endphp) or as a standalone renderer for non-Blade contexts (e.g., API responses).e() helper) may be needed.e() helper escapes output, but HtmlElement renders raw HTML. Risk of XSS if user input is interpolated directly (mitigate via htmlspecialchars or Laravel’s e() wrapper).safeEl()) be needed?collective/html or livewire/html if UI components are the primary use case.Markdown::render() for complex HTML emails.str_replace() with el() calls.HtmlElement::render() in a helper (e.g., app(HtmlElement::class)->render()) for consistency.el() for dynamic sections (e.g., @php echo el('user-card', [...]) @endphp).assertHtmlEquals or visual regression tools).@php directives for dynamic rendering.HtmlElement to integrate with Laravel’s e() helper (e.g., modify the renderer to escape attributes by default).el('img', ['src' => asset('image.jpg')])).Mailable class (replace view() with el() for dynamic content).safeEl() wrapper or middleware).safeEl() pattern and enforce it via static analysis (e.g., PHPStan).debug() method to HtmlElement to inspect rendered output during development.fallbackToBlade() helper for complex cases where el() is cumbersome.Cache::remember()).el() syntax and escaping rules.| Risk | Mitigation |
|---|---|
| XSS via user input | Enforce safeEl() wrapper or attribute escaping in all public-facing output. |
| Breaking changes | Pin version in composer.json until stability is confirmed. |
| Syntax errors | Use IDE autocompletion and add tests for critical templates. |
| Integration with Blade | Document hybrid usage patterns (e.g., @php echo el(...) @endphp). |
| Asset path issues | Validate asset()/mix() usage in generated HTML. |
el() syntax, escaping, and common patterns (e.g., forms, tables).el() maps to their HTML/CSS (e.g., el('div.container > ...)).phpstan.neon rule to detect unescaped el() calls with user input.HtmlElementTestCase base class for unit tests.How can I help you explore Laravel packages today?