← ClaudeAtlas

twig-componentlisted

Symfony UX TwigComponent for reusable UI elements. Use when creating reusable Twig templates with PHP backing classes, component composition, props, slots/blocks, computed properties, or anonymous components. Triggers - twig component, AsTwigComponent, reusable template, component props, twig blocks, component slots, anonymous component, Symfony UX component, HTML component, component library, design system component, UI kit, reusable button, reusable card, PreMount, PostMount, mount method. Also trigger for any question about building a reusable piece of UI in Symfony, even if the user doesn't mention TwigComponent by name.
BKR-57/symfony-ux-skills · ★ 0 · Web & Frontend · score 75
Install: claude install-skill BKR-57/symfony-ux-skills
# TwigComponent Reusable UI components with PHP classes + Twig templates. Think React/Vue components, but server-rendered with zero JavaScript. Two flavors exist: **class components** (PHP class + Twig template) for components that need logic, services, or computed properties, and **anonymous components** (Twig-only, no PHP class) for simple presentational elements. ## When to Use TwigComponent Use TwigComponent when you need reusable markup with props but no server re-rendering after the initial render. If the component needs to react to user input (re-render via AJAX, data binding, actions), use LiveComponent instead. Good candidates: buttons, alerts, cards, badges, icons, form widgets, layout sections, navigation items, table rows, modals (structure only). ## Installation ```bash composer require symfony/ux-twig-component ``` ## Class Component A PHP class annotated with `#[AsTwigComponent]` paired with a Twig template. ```php // src/Twig/Components/Alert.php namespace App\Twig\Components; use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; #[AsTwigComponent] final class Alert { public string $type = 'info'; public string $message; public bool $dismissible = false; } ``` ```twig {# templates/components/Alert.html.twig #} <div class="alert alert-{{ type }}" {{ attributes }}> {{ message }} {% if dismissible %} <button type="button" class="close">&times;</button> {% endif %} </div> ``` ```twig {# Usage #} <twig:Alert type="suc