symfony-ux-twig-component

Define reusable Symfony Twig components backed by PHP classes.

1|Updated Mar 25, 2026
One-click install
npx skills add https://github.com/woweya/Symfony-UX-LiveComponent-Skill --skill symfony-ux-twig-component
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: symfony-ux-twig-component
Source: https://github.com/woweya/Symfony-UX-LiveComponent-Skill/tree/main/skills/symfony-ux-twig-component
Command: npx skills add https://github.com/woweya/Symfony-UX-LiveComponent-Skill --skill symfony-ux-twig-component

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Symfony + Twig components are powerful but manual boilerplate is repetitive. This Skill outlines how to build reusable Twig Components with PHP backing to streamline UI development in Symfony UX projects.

Core Features & Use Cases

  • Prop-driven PHP-backed components: public properties become component props, with support for default values and computed accessors.
  • Slots, composition, and anonymous components: compose reusable UI blocks with named slots and optional template-only components.
  • Lifecycle hooks and customization: PreMount and PostMount hooks for prop validation and post-setup logic; custom names and templates.
  • Designer-friendly usage: straightforward authoring with AsTwigComponent attributes and Twig usage via twig:YourComponent.

Quick Start

Define a Twig component by annotating a PHP class with AsTwigComponent, create a matching Twig template, and render it with the twig:Component tag.

Frequently Asked Questions about symfony-ux-twig-component

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create reusable Twig components with PHP backing in Symfony?

To create reusable Twig components with PHP backing in Symfony, you annotate a PHP class with the AsTwigComponent attribute, define public properties to act as component props, and render the UI block using the twig:Component tag in your templates.

How do Twig component slots work for composing server-rendered UI blocks?

Twig component slots allow you to compose server-rendered UI blocks by injecting content into defined areas within your component template. You can use named slots for targeted content placement and anonymous components for template-only UI pieces.

Can I use lifecycle hooks to validate props in Symfony Twig components?

Yes, you can use lifecycle hooks to validate props in Symfony Twig components. The PreMount hook allows you to intercept and validate incoming props before rendering, while the PostMount hook executes post-setup logic after the component is instantiated.

What is the best way to pass data to server-rendered Twig components?

The best way to pass data to server-rendered Twig components is by defining public properties in your PHP class, which automatically become component props. You can set default values and use computed accessors to dynamically derive data when rendering with the twig: tag.

Do I need to manually configure template naming conventions for Twig components?

You do not need to manually configure template naming conventions for Twig components. Symfony UX automatically resolves the matching Twig template based on the component class name, though you can specify custom names and templates if needed.

When should I use anonymous Twig components instead of PHP-backed ones?

You should use anonymous Twig components instead of PHP-backed ones when you need straightforward, template-only UI blocks that do not require PHP logic. This approach is designer-friendly and eliminates the need for a backing PHP class when rendering server-side UI.