twig-components
Installation
SKILL.md
Twig Components (Symfony)
Use when
- Extracting a repeated piece of Twig into a reusable component.
- Building a component with props, slots, computed logic, or CVA variants.
- Making a component reactive with Live Components (search, counters, forms).
Default workflow
- Choose the kind: anonymous (template only), class-based
#[AsTwigComponent], or#[AsLiveComponent]. - Declare props as public mutable properties; use
mount()for derived values. - Expose content injection through blocks (slots) rather than more props.
- For Live Components, mark writable state with
#[LiveProp(writable: true)]and debounce user input. - Test the PHP class with
InteractsWithTwigComponents.
Guardrails
- Never make public props
readonly: they are assigned after instantiation. - Inject services as
private readonly, never as public props. - Only mark a
LivePropwritable when the browser must change it. - Keep one responsibility per component.