Agent skill

Twig Component

by smnandre in smnandre/symfony-ux-skills

Symfony UX TwigComponent for reusable UI building blocks -- server-rendered components with PHP classes and Twig templates.

MITAuto-check passedFrontend & Design

Install Twig Component

skills CLI
$ npx skills add smnandre/symfony-ux-skills --skill twig-component -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install smnandre/symfony-ux-skills twig-component --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/smnandre/symfony-ux-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/twig-component .claude/skills/twig-component && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
twig-component
GitHub stars
180
Token cost
~2.5k tokens
SKILL.md length
381 words
Files
4 (incl. references)
Skills in repo
7
Repo updated
First seen
Licence
MIT

At a glance

Symfony UX TwigComponent for reusable UI building blocks -- server-rendered components with PHP classes and Twig templates.

  • Creating buttons
  • SKILL.md covers When to Use TwigComponent, Installation, Class Component and Anonymous Component (Twig Only), plus 11 more sections
  • Calls composer
  • Any reusable UI element with props

What it does

Twig Component is an agent skill from smnandre/symfony-ux-skills. Symfony UX TwigComponent for reusable UI building blocks -- server-rendered components with PHP classes and Twig templates. Use when creating buttons, cards, alerts, badges, navbars, or any reusable UI element with props, blocks/slots, computed properties, or anonymous (template-only) components. Code triggers: AsTwigComponent, [AsTwigComponent], ExposeInTemplate, PreMount, PostMount, <twig:Alert /, <twig:Button, component(), computed properties, anonymous component, HTML syntax. Also trigger when the user asks…

Its SKILL.md is about 2.5k tokens, which your agent loads only when the skill is triggered. The skill folder holds 4 other files, including reference files (for example `references/api.md`, `references/gotchas.md` and `references/patterns.md`).

It sits in Frontend & Design, covering Design systems. It works with Symfony, PHP and Google Gemini. The repository describes itself as: Symfony UX skills for Claude, Gemini, Codex, ... Live Component, Twig Component, Turbo, Stimulus. The licence is MIT.

When your agent uses it

  • Creating buttons
  • Any reusable UI element with props
  • Computed properties
  • Anonymous (template-only) components

Example prompts

  • “how to create a reusable component”
  • “how to make a component library”
  • “how to pass props to a component”
  • “/twig-component”

What it can do on your machine

Read from SKILL.md and the folder at commit 1e99301. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • composer

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Twig Component loads about 2.5k tokens when it runs, and up to ~9.3k if it reads all its reference files. Until then it costs about 245 tokens; SKILL.md has 381 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~245
When it runs · the whole SKILL.md, loaded when a task matches
~2.5k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~9.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from smnandre/symfony-ux-skills at commit 1e99301, republished under its MIT licence (© smnandre). 381 words, ~2,463 tokens.

Download SKILL.mdSave it as .claude/skills/twig-component/SKILL.md (or your agent's skills folder). This skill also uses 3 other files; get the full folder from GitHub.
name
twig-component
description
Symfony UX TwigComponent for reusable UI building blocks -- server-rendered components with PHP classes and Twig templates. Use when creating buttons, cards, alerts, badges, navbars, or any reusable UI element with props, blocks/slots, computed properties, or anonymous (template-only) components. Code triggers: AsTwigComponent, #[AsTwigComponent], ExposeInTemplate, PreMount, PostMount, <twig:Alert />, <twig:Button>, component(), computed properties, anonymous component, HTML syntax. Also trigger when the user asks "how to create a reusable component", "how to make a component library", "how to pass props to a component", "how to use slots/blocks in a component", "how to build a design system in Symfony", "what is the HTML syntax for components", "how to create a component without a PHP class". Do NOT trigger for components that re-render dynamically on user input (use live-component), for JS behavior (use stimulus), or for page navigation (use turbo).
license
MIT
metadata.author
Simon Andre
metadata.email
smn.andre@gmail.com
metadata.url
https://smnandre.dev
metadata.version
1.2.0

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="success" message="Saved!" />
<twig:Alert type="danger" message="Error occurred" dismissible />

{# With block content instead of message prop #}
<twig:Alert type="warning">
    <strong>Warning:</strong> Check your input
</twig:Alert>

Anonymous Component (Twig Only)

No PHP class needed. Props are declared with {% props %} directly in the template. Use for simple presentational components with no logic.

twig
{# templates/components/Button.html.twig #}
{% props variant = 'primary', size = 'md', disabled = false %}

<button
    class="btn btn-{{ variant }} btn-{{ size }}"
    {{ disabled ? 'disabled' }}
    {{ attributes }}
>
    {% block content %}{% endblock %}
</button>
twig
<twig:Button variant="danger" size="lg">Delete</twig:Button>

Props

Public Properties (Class Components)

Public properties become props. Required props have no default value.

php
#[AsTwigComponent]
final class Card
{
    public string $title;           // Required
    public ?string $subtitle = null; // Optional
    public bool $shadow = true;      // Optional with default
}
mount() for Derived State

Use mount() to compute values from incoming props. The method runs once during component initialization.

php
#[AsTwigComponent]
final class UserCard
{
    public User $user;
    public string $displayName;

    public function mount(User $user): void
    {
        $this->user = $user;
        $this->displayName = $user->getFullName();
    }
}
twig
<twig:UserCard :user="currentUser" />
Dynamic Props (Colon Prefix)

Prefix a prop with : to pass a Twig expression instead of a string literal.

twig
{# Pass a variable #}
<twig:Alert :type="alertType" :message="flashMessage" />

{# Pass an expression #}
<twig:UserList :users="users|filter(u => u.active)" />

Blocks (Slots)

Blocks let parent templates inject content into specific areas of a component.

Default Block

Content between component tags goes to {% block content %}:

twig
{# Component template #}
<div class="card">{% block content %}{% endblock %}</div>

{# Usage #}
<twig:Card><p>This is the card content</p></twig:Card>
Named Blocks
twig
{# templates/components/Modal.html.twig #}
<dialog class="modal" {{ attributes }}>
    <header>{% block header %}Default Header{% endblock %}</header>
    <main>{% block content %}{% endblock %}</main>
    <footer>{% block footer %}{% endblock %}</footer>
</dialog>
twig
<twig:Modal>
    <twig:block name="header"><h2>Confirm Action</h2></twig:block>
    <twig:block name="content"><p>Are you sure?</p></twig:block>
    <twig:block name="footer">
        <button>Cancel</button>
        <button>Confirm</button>
    </twig:block>
</twig:Modal>
Show full SKILL.md (161 more words)Show less

Computed Properties

Methods prefixed with get become accessible as this.xxx in templates. They are computed on each access (not cached across re-renders -- for caching, see LiveComponent's computed).

php
#[AsTwigComponent]
final class ProductCard
{
    public Product $product;

    public function getFormattedPrice(): string
    {
        return number_format($this->product->getPrice(), 2) . ' EUR';
    }

    public function isOnSale(): bool
    {
        return $this->product->getDiscount() > 0;
    }
}
twig
<div class="product">
    <span class="price">{{ this.formattedPrice }}</span>
    {% if this.onSale %}
        <span class="badge">Sale!</span>
    {% endif %}
</div>

Attributes

Extra HTML attributes passed to the component are available via {{ attributes }}. This is how you let consumers add custom classes, ids, data attributes, etc.

twig
{# Usage #}
<twig:Alert type="info" message="Hello" class="my-class" id="main-alert" data-controller="alert" />

{# In component template -- renders class, id, data-controller #}
<div {{ attributes }}>...</div>
Attributes Methods
twig
{# Merge with defaults #}
<div {{ attributes.defaults({class: 'alert'}) }}>

{# Exclude specific #}
<div {{ attributes.without('id', 'class') }}>

{# Only render specific #}
<div id="{{ attributes.render('id') }}">

{# Check existence #}
{% if attributes.has('disabled') %}

Components as Services

Components are Symfony services -- autowiring works naturally. Use the constructor for dependencies, public properties for props.

php
#[AsTwigComponent]
final class FeaturedProducts
{
    public function __construct(
        private readonly ProductRepository $products,
    ) {}

    public function getProducts(): array
    {
        return $this->products->findFeatured(limit: 6);
    }
}
twig
{# templates/components/FeaturedProducts.html.twig #}
<div class="featured-products">
    {% for product in this.products %}
        <twig:ProductCard :product="product" />
    {% endfor %}
</div>
twig
{# Usage -- no props needed, data comes from service #}
<twig:FeaturedProducts />

Lifecycle Hooks

php
use Symfony\UX\TwigComponent\Attribute\PreMount;
use Symfony\UX\TwigComponent\Attribute\PostMount;

#[AsTwigComponent]
final class DataTable
{
    public array $data;
    public string $sortBy = 'id';

    #[PreMount]
    public function preMount(array $data): array
    {
        // Modify/validate incoming data before property assignment
        $data['sortBy'] ??= 'id';
        return $data;
    }

    #[PostMount]
    public function postMount(): void
    {
        // Runs after all props are set
        $this->data = $this->sortData($this->data);
    }
}

Nested Components

Components compose naturally -- nest them like HTML elements:

twig
<twig:Card>
    <twig:block name="header">
        <twig:Icon name="star" /> Featured
    </twig:block>
    <twig:block name="content">
        <twig:ProductList :products="featuredProducts">
            <twig:block name="empty">
                <twig:Alert type="info" message="No products found" />
            </twig:block>
        </twig:ProductList>
    </twig:block>
</twig:Card>

Configuration

yaml
# config/packages/twig_component.yaml
twig_component:
    anonymous_template_directory: 'components/'
    defaults:
        App\Twig\Components\: 'components/'

HTML vs Twig Syntax

twig
{# HTML syntax (recommended -- better IDE support, more readable) #}
<twig:Alert type="success" message="Done!" />

{# Twig syntax (alternative -- useful in edge cases) #}
{% component 'Alert' with {type: 'success', message: 'Done!'} %}
{% endcomponent %}

Prefer HTML syntax (<twig:...>) in all cases. The Twig syntax ({% component %}) is legacy and less readable.

References

See Also

  • UX Icons integrates naturally in TwigComponent templates: <twig:ux:icon name="lucide:check" /> inside your component markup.
  • UX Map can be rendered inside a TwigComponent template via {{ ux_map(map, {style: 'height: 400px;'}) }}.

© smnandre, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 3 other files (references) in skills/twig-component of smnandre/symfony-ux-skills.

  • SKILL.md
  • references/api.md
  • references/gotchas.md
  • references/patterns.md

Open the folder on GitHubat commit 1e99301

Compare with similar skills

Twig Component next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Twig Component compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Twig Component this skillsmnandre/symfony-ux-skills180—~2.5kAutomated safety check: PassMIT
Yuv Pilothoodini/ai-agents-skills281—~4.7kAutomated safety check: PassNone
UI Design ReviewMadAppGang/claude-code284—~2kAutomated safety check: PassMIT
Impeccablebestofjs/bestofjs3.1k27 repos~2.6kAutomated safety check: PassMIT
Figma Design System Builderwarpdotdev/warp65k2 repos~4.4kAutomated safety check: PassAGPL-3.0
Tailwindcss Developmentanonaddy/anonaddy4.9k10 repos~865Automated safety check: PassMIT

Similar skills

  • Yuv Pilot

    hoodini/ai-agents-skills

    Top-of-pyramid orchestrator for Yuval Avidani's YUV.AI brand work.

    281 GitHub stars~4.7k tokensUpdated 2 mo ago
    Frontend & DesignAuto-check passed
  • UI Design Review

    MadAppGang/claude-code

    Prompting patterns and review templates for UI design analysis with Gemini multimodal capabilities.

    284 GitHub stars~2k tokensUpdated 6 mo ago
    Frontend & DesignAuto-check passed
  • Impeccable

    bestofjs/bestofjs

    A skill your agent uses when the user wants to design, redesign, shape, critique, audit, polish, clarify, distill, harden, optimize, adapt, animate, colorize, extract, or otherwise improve a…

    3.1k GitHub starsUsed in 27 repos~2.6k tokens
    Frontend & DesignAuto-check passed
  • Builds or updates a design system in Figma from a codebase in ordered phases: discovery, variables and tokens, components, theming and documentation, with checkpoints.

    65k GitHub starsUsed in 2 repos~4.4k tokens
    Frontend & DesignAuto-check passed
  • Tailwindcss Development

    anonaddy/anonaddy

    Always invoke when the user's message includes 'tailwind' in any form.

    4.9k GitHub starsUsed in 10 repos~865 tokens
    Frontend & DesignAuto-check passed
  • Required groundwork before any use_figma call: the rules and reference files for running JavaScript in a Figma file through the Plugin API without common failures.

    65k GitHub starsUsed in 4 repos~4.4k tokens
    Frontend & DesignAuto-check passed

More from smnandre/symfony-ux-skills

  • Live Component

    smnandre/symfony-ux-skills

    Symfony UX LiveComponent for reactive server-rendered UI -- components that re-render via AJAX on user interaction, zero JavaScript required.

    180 GitHub stars~3.3k tokensUpdated 3 mo ago
    Auto-check passed
  • Stimulus

    smnandre/symfony-ux-skills

    Stimulus JS framework for Symfony UX -- client-side behavior via HTML data attributes, zero server round-trips.

    180 GitHub stars~2.1k tokensUpdated 3 mo ago
    Auto-check passed
  • Turbo

    smnandre/symfony-ux-skills

    Hotwire Turbo for Symfony UX -- SPA-like speed with zero JavaScript.

    180 GitHub stars~2.9k tokensUpdated 3 mo ago
    Auto-check passed
  • UX Icons

    smnandre/symfony-ux-skills

    Symfony UX Icons for rendering SVG icons in Twig templates. An agent skill from smnandre/symfony-ux-skills.

    180 GitHub stars~1.9k tokensUpdated 3 mo ago
    Auto-check passed
  • UX Map

    smnandre/symfony-ux-skills

    Symfony UX Map for interactive maps with Leaflet or Google Maps in Symfony.

    180 GitHub stars~3k tokensUpdated 3 mo ago
    Auto-check: notes
  • Symfony UX

    smnandre/symfony-ux-skills

    Symfony UX frontend stack -- decision tree and orchestrator for choosing between Stimulus, Turbo, TwigComponent, LiveComponent, UX Icons, and UX Map.

    180 GitHub stars~3.4k tokensUpdated 3 mo ago
    Auto-check passed

Questions about Twig Component

What does Twig Component do?

Symfony UX TwigComponent for reusable UI building blocks -- server-rendered components with PHP classes and Twig templates. Twig Component is an agent skill from smnandre/symfony-ux-skills. Symfony UX TwigComponent for reusable UI building blocks -- server-rendered components with PHP classes and Twig templates.

When should I use Twig Component?

Twig Component fits situations like: creating buttons; any reusable UI element with props; computed properties; anonymous (template-only) components.

How do I install Twig Component in Claude Code?

Run `npx skills add smnandre/symfony-ux-skills --skill twig-component -a claude-code`. Or copy the skill folder (skills/twig-component in smnandre/symfony-ux-skills) into .claude/skills/twig-component in your project. Claude Code loads it when a task matches its description.

How do I install Twig Component in Codex?

Run `npx skills add smnandre/symfony-ux-skills --skill twig-component -a codex`. Or copy the skill folder (skills/twig-component in smnandre/symfony-ux-skills) into .agents/skills/twig-component in your project. Codex loads it when a task matches its description.

Can I use Twig Component in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add smnandre/symfony-ux-skills --skill twig-component -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/twig-component, .gemini/skills/twig-component, .github/skills/twig-component and .opencode/skills/twig-component in your project.

What does Twig Component need to run?

Going by SKILL.md and its folder, Twig Component needs the command-line tools its instructions call (composer).

Does Twig Component access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Twig Component safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Twig Component use?

Twig Component is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Twig Component use?

About 2.5k tokens (SKILL.md is roughly 9.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 6.8k tokens, read only when the agent opens those files.

What are the alternatives to Twig Component?

Skills that share tags, products or a category with Twig Component: Yuv Pilot (hoodini/ai-agents-skills, 281 stars), UI Design Review (MadAppGang/claude-code, 284 stars), Impeccable (bestofjs/bestofjs, 3.1k stars) and Figma Design System Builder (warpdotdev/warp, 65k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Twig Component?

smnandre (a GitHub user) maintains it in smnandre/symfony-ux-skills, which has 180 GitHub stars. The repository holds 7 skills in this directory. The repository was last updated on June 14, 2026.

Source: smnandre/symfony-ux-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.