twig-component

Create reusable UI components for Symfony UX using Twig templates and PHP classes.

166|12|Updated Mar 2, 2026
One-click install
npx skills add https://github.com/smnandre/symfony-ux-skills --skill twig-component
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: twig-component
Source: https://github.com/smnandre/symfony-ux-skills/tree/main/skills/twig-component
Command: npx skills add https://github.com/smnandre/symfony-ux-skills --skill twig-component

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Symfony UX TwigComponent enables building reusable UI blocks that can be composed and shared across templates, reducing duplication and maintenance.

Core Features & Use Cases

  • Class-based components with PHP backing and Twig templates for logic-heavy widgets.
  • Anonymous Twig components for simple presentational blocks that require no PHP.
  • Props, blocks/slots, computed properties, and dynamic attributes for flexible design.
  • Suitable for building design-system components like cards, buttons, modals, forms, and dashboards.

Quick Start

Create a small reusable Button TwigComponent and render it in a page to verify the workflow.

Frequently Asked Questions about twig-component

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

FAQPage Schema
How do I build reusable UI components for Symfony UX templates?

Symfony UX TwigComponent lets you build reusable UI components by creating class-based PHP components or anonymous Twig-only blocks, defining props and blocks, then rendering them across templates to eliminate duplication.

What is the difference between class-based and anonymous Twig components?

Class-based Twig components use PHP backing and the AsTwigComponent attribute for logic-heavy widgets, while anonymous Twig components are purely presentational blocks defined in Twig templates without any PHP class required.

Do I need the Symfony UX TwigComponent integration to use Twig components?

Yes, you need the Symfony UX TwigComponent integration installed and configured in your Symfony project, along with the AsTwigComponent attribute, to enable class-based component functionality, props, blocks, and lifecycle hooks.

Can I pass dynamic attributes and props to Twig components in Symfony?

Yes, Twig components support props, computed properties, blocks or slots, and dynamic attributes, allowing you to build flexible design-system components like cards, buttons, modals, forms, and dashboards with customizable inputs.

What's the best way to structure a design system using Twig components?

The best way to structure a design system with Twig components is to create reusable class-based or anonymous components for UI elements like cards and modals, using props and blocks to manage presentation variations and reduce maintenance.

When should I avoid using Twig components for frontend templating?

You should avoid using Twig components when a template block requires no reuse or composition, as the overhead of defining props and PHP backing for simple, one-off presentational markup outweighs the benefits of componentization.