/symfony:twig-conventionsfrom symfony
Enforces Twig component creation guidelines and translation domain isolation in Symfony templates. Helps decide when to use components and avoid translation pitfalls.
Ships in symfony. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Critical pitfalls and decision rules for Twig templates and components.
<twig:*>)A Twig component is only justified if it encapsulates complex logic — either in the component itself or in its PHP class. Use HTML directly otherwise.
{# WRONG — Twig component with no logic #}
<twig:Marker />
{# CORRECT — Direct HTML #}
<span class="marker"></span>
A component without logic adds overhead (YAML registration, PHP file, Twig file) for zero benefit. Raw HTML is more readable, faster to render, and easier to grep.
Before creating MyComponent.php + MyComponent.html.twig, answer:
If all three answers are "no", write inline HTML + class. You can always extract to a component later when the need emerges.
IMPORTANT: Twig components (<twig:*>) are isolated and do NOT inherit trans_default_domain from the parent template.
When using trans_default_domain in a parent template, child content passed to a Twig component does NOT inherit this domain:
{# Parent template #}
{% trans_default_domain 'my_domain' %}
<twig:Button>
{{ 'my_key'|trans }} {# WRONG: Will look in 'messages' domain, not 'my_domain' #}
</twig:Button>
There are two acceptable ways to set the domain inside a Twig component, depending on how many translations the component content holds.
domain:When there is a single |trans call inside the component content, pass the domain inline. No need to add a setup line for one call.
<twig:Alert>
<twig:block name="content">{{ 'warning'|trans(domain: 'my_domain') }}</twig:block>
</twig:Alert>
{% trans_default_domain %} onceWhen the component content contains 2+ |trans calls, declare {% trans_default_domain %} once at the top of the content rather than repeating (domain: '...') on every line. Repetition is a refactor liability — change the domain once and you've shifted N spots.
<twig:Table>
{% trans_default_domain 'my_domain' %}
<thead>
<tr>
<th>{{ 'col.name'|trans }}</th>
<th>{{ 'col.type'|trans }}</th>
<th>{{ 'col.isin'|trans }}</th>
<th>{{ 'col.sri'|trans }}</th>
<th>{{ 'col.allocation'|trans }}</th>
</tr>
</thead>
{# ... #}
</twig:Table>
The trans_default_domain declared inside the component's content scope applies within that isolated scope.
Twig components process their content in isolation. The trans_default_domain tag sets a variable in the current template scope, but component content is evaluated in a separate context where the parent's variable is not accessible. Re-declaring trans_default_domain inside the component content sets it in that inner scope.
{% extends 'base.html.twig' %}
{% block body %}
{% trans_default_domain 'order_checkout' %}
{# Direct translation in template scope — inherits trans_default_domain #}
<h1>{{ 'title'|trans }}</h1>
{# 1 translation inside a component — inline domain #}
<twig:Alert>
<twig:block name="content">{{ 'warning'|trans(domain: 'order_checkout') }}</twig:block>
</twig:Alert>
{# 2+ translations inside a component — hoist trans_default_domain #}
<twig:Table>
{% trans_default_domain 'order_checkout' %}
<thead>
<tr>
<th>{{ 'col.name'|trans }}</th>
<th>{{ 'col.qty'|trans }}</th>
<th>{{ 'col.price'|trans }}</th>
</tr>
</thead>
</twig:Table>
{% endblock %}
IMPORTANT: Never use Twig date functions directly in templates. Inject a ClockInterface (PSR-20) via a Twig component, a controller, or a Twig function/extension.
{# WRONG: Global function in the template #}
<footer>Acme {{ "now"|date("Y") }}</footer>
Issues:
// src/Twig/Component/Layout.php
final class Layout
{
public function __construct(private readonly ClockInterface $clock) {}
public function getCurrentYear(): string
{
return $this->clock->now()->format('Y');
}
}
<footer>Acme {{ this.currentYear }}</footer>
// In the controller
return $this->render('template.html.twig', [
'currentYear' => $this->clock->now()->format('Y'),
]);
<footer>Acme {{ currentYear }}</footer>
// src/Twig/Extension/DateExtension.php
final class DateExtension extends AbstractExtension
{
public function __construct(private readonly ClockInterface $clock) {}
public function getFunctions(): array
{
return [
new TwigFunction('current_year', $this->getCurrentYear(...)),
];
}
public function getCurrentYear(): string
{
return $this->clock->now()->format('Y');
}
}
<footer>Acme {{ current_year() }}</footer>
Psr\Clock\ClockInterface)The parent's trans_default_domain does not propagate into:
<twig:*> component contentPick the form based on call count:
(domain: '...'){% trans_default_domain '...' %} once at the top of that scope| Context | Inherits parent trans_default_domain | 1 translation | 2+ translations |
|---|---|---|---|
| Direct in template | Yes | {{ 'key'|trans }} | {{ 'key'|trans }} |
Inside <twig:Component> | No | {{ 'key'|trans(domain: 'd') }} | {% trans_default_domain 'd' %} then {{ 'key'|trans }} |
| Inside macro (same file) | Yes | {{ 'key'|trans }} | {{ 'key'|trans }} |
| Inside imported macro | Depends | {{ 'key'|trans(domain: 'd') }} | {% trans_default_domain 'd' %} then {{ 'key'|trans }} |
When a translation key appears as-is instead of translated:
translations/{domain}.{locale}.yaml existssection.subsection.keybin/console cache:clearWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
5 skills in this plugin
/prg-patternACTIVATE when implementing form handling, POST endpoints, or any controller that modifies data. ACTIVATE for 'form submission', 'POST redirect', 'PRG', 'duplicate submission'. Covers: POST success always redirects, POST error re-renders (no redirect), flash messages after redirect. DO NOT use for: FormType design (see symfony:symfony-form), API endpoints returning JSON./symfony-formACTIVATE when working with Symfony FormTypes, form handling, data_class, DataTransformers, form options, or property_path. ACTIVATE when creating or modifying any FormType class. Covers: data_class as single source of truth (no data in options), DataTransformer placement (not controller), property_path for collection mapping. DO NOT use for: form submission flow/PRG (see symfony:prg-pattern), form validation rules, general Symfony questions./symfony-frontendACTIVATE when adding or modifying frontend behaviour in a Symfony project — any new feature whose Twig template would otherwise contain inline script or style blocks, or any new JS/CSS file to load for a specific page. ACTIVATE for 'inline script in twig', 'inline style in twig', 'WebpackEncore', 'addEntry', 'encore_entry_link_tags', 'encore_entry_script_tags', 'where to put my JS', 'how to load CSS for one page', 'FormType injecting class', 'js- hook in template'. Covers: forbidden inline script/style tags in Twig, one Encore entry per feature, per-page asset loading via stylesheets/javascripts blocks extending parent, SCSS imported by the JS module (one entry bundles both), FormType stays domain/server (no CSS-only classes via `attr`), `js-*` hooks added at render time. DO NOT use for: jQuery style (see jquery:jquery), Twig conventions (see symfony:twig-conventions), FormType conventions (see symfony:symfony-form), autonomous visual debugging (see frontend:frontend-best-practices)./symfony-test-conventionsACTIVATE when writing or modifying a test that boots Symfony — WebTestCase, KernelTestCase, TypeTestCase, functional/interface tests, FormType tests, or container service doubles. ACTIVATE for 'crawler', 'assertSelectorTextContains', 'assertResponseRedirects', 'assertSelectorExists', 'followRedirect', 'disableReboot', 'getContainer() set', 'TypeTestCase', 'functional test', 'test fonctionnel', 'test d'interface'. Covers: which base class to pick, built-in WebTestCase assertions over hand-rolled crawler reads, one-dataset-one-test for HTML pages, full-JSON assertion for API endpoints, FormType testing, and container-double traps. DO NOT use for: PHPUnit/Prophecy patterns independent of Symfony — doubles, data providers, test naming, factories (see phpunit:php-test-conventions), TDD workflow (see phpunit:php-tdd-workflow), FormType design itself (see symfony:symfony-form).npx claudepluginhub fabiensalles/claude-marketplace --plugin symfony