/symfony:symfony-frontendfrom symfony
Organizes frontend assets in Symfony projects: forbids inline script/style in Twig, creates one Webpack Encore entry per feature, loads per-page assets via parent-extending blocks, and uses js-* hooks for JS binding.
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.
Where JS, CSS and Twig live in a Symfony project, and how they connect through Webpack Encore. The code style of the JS itself (jQuery patterns, selectors) is covered by
jquery:jquery— this skill only covers the organization.
<script> or <style> in TwigTwig templates carry markup and translation. JS lives in .js files, CSS in .scss files. Always.
{# ❌ Inline JS #}
{% block body %}
<button id="trigger">Toggle</button>
<script>document.getElementById('trigger').addEventListener('click', () => { /* … */ });</script>
{% endblock %}
{# ❌ Inline CSS #}
{% block body %}
<style>.my-class { background: white; }</style>
{% endblock %}
{# ✅ #}
{% block stylesheets %}
{{ parent() }}
{{ encore_entry_link_tags('my-feature') }}
{% endblock %}
{% block javascripts %}
{{ parent() }}
{{ encore_entry_script_tags('my-feature') }}
{% endblock %}
{% block body %}
<button class="js-trigger">Toggle</button>
{% endblock %}
Why: inline blocks aren't bundled, aren't minified, aren't cacheable, can't share imports, run at parse time (before DOM ready), and bury logic where it can't be grepped.
Each feature has its own addEntry in webpack.config.js:
Encore
// …
.addEntry('main', './assets/main.js') // global
.addEntry('suitability', './assets/features/proposal/suitability.js') // per page
.addEntry('my-feature', './assets/features/proposal/my-feature.js') // per page
Naming: kebab-case, matches the feature, not the page name (the same feature might be used on multiple pages later).
File location: assets/features/<bounded-context>/<feature>.js. Mirror the backend's bounded contexts when possible (assets/features/proposal/..., assets/features/customer/...).
The JS module imports its own SCSS at the top. Encore bundles both into the same entry's link_tags / script_tags.
// assets/features/proposal/my-feature.js
import './my-feature.scss';
export const initMyFeature = () => { /* … */ };
$(document).ready(() => initMyFeature());
/* assets/features/proposal/my-feature.scss */
.js-my-feature-block textarea[readonly] {
background-color: #fff;
}
Don't: dump feature CSS in assets/main.scss. That file is for global rules (resets, design-system overrides, utilities used everywhere). Feature CSS stays with its feature.
{% block stylesheets %} / {% block javascripts %} Always Extend ParentThe base template often loads global bundles (main, theme-bundle, etc.). A per-page template adds its entry — never replaces.
{# ✅ #}
{% block stylesheets %}
{{ parent() }}
{{ encore_entry_link_tags('my-feature') }}
{% endblock %}
{# ❌ Forgets {{ parent() }} — base CSS is lost on this page #}
{% block stylesheets %}
{{ encore_entry_link_tags('my-feature') }}
{% endblock %}
js-* Hooks Added in the Template, Not in the FormTypeThe FormType describes the domain shape of the form (types, options, constraints). It must not inject CSS-only or JS-only classes via attr — those are presentation concerns that belong to the template.
// ❌ FormType polluted by frontend concerns
->add('proposal_context', TextareaType::class, [
'attr' => [
'readonly' => true,
'class' => 'js-my-feature-textarea', // CSS hook injected server-side
],
])
// ✅ FormType stays domain-oriented
->add('proposal_context', TextareaType::class, [
'attr' => ['readonly' => true],
])
{# Template adds the JS hook at render time #}
{{ form_widget(form.proposal_context, {attr: {class: 'js-my-feature-textarea'}}) }}
Why: the FormType is reused (rendered into different templates, tested in isolation). Coupling it to a specific CSS class means every test, every reuse, every refactor of the styling carries the FormType along. Keep the seam clean.
readonly is semantic (the form is sometimes read-only) — that belongs in the FormType. js-* is presentational (this rendering uses JS) — that belongs in the template.
js-* Wrapper, Not FormType-Generated ClassesA CSS rule must never depend on a class auto-injected by Symfony Forms (e.g. .form-control, .is-invalid) or by your FormType's attr. Target the wrapper the template added, plus a generic element/state.
/* ✅ */
.js-my-feature-block textarea[readonly] {
background-color: #fff;
}
/* ❌ Fragile if FormType options change */
.commercial-proposal__textarea {
background-color: #fff;
}
For one-rule features, the js-* wrapper class doubles as the CSS hook. Splitting into a separate styling class is over-engineering.
Specificity reminder: .js-foo-block textarea[readonly] is (0, 2, 1), beating Bootstrap's .form-control[readonly] (0, 2, 0). No !important needed.
assets/features/<context>/<feature>.jsassets/features/<context>/<feature>.scss, imported by the JS file.addEntry('<feature>', './assets/features/<context>/<feature>.js') in webpack.config.js{% block stylesheets %} and {% block javascripts %} with the entry tags, both with {{ parent() }} first<script> or <style> block in the templateclass: 'js-…' in the FormType attr — added at render time in the templatejs-* wrapper + a generic element/state, never a FormType-generated class| Situation | Approach |
|---|---|
| Need JS on a page | Module under assets/features/<context>/<feature>.js, new Encore entry |
| Need CSS for one feature | .scss next to the JS, import './feature.scss' from the JS |
| Load assets for one page | {% block stylesheets %} + {% block javascripts %}, extend parent() |
| Need a CSS class for styling on a field | Add via the template (form_widget(..., {attr: {class: 'js-foo'}}) |
| Need a CSS class for JS hooking | Same — never via the FormType attr |
| Want to share styles across the whole app | assets/main.scss |
| Want to share styles across one feature | Feature .scss, imported by the feature module |
| jQuery code style for the module itself | See jquery:jquery skill |
What 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-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)./twig-conventionsACTIVATE when writing or modifying Twig templates, using Twig components (twig:*), handling translations in Twig, debugging translation issues, or deciding whether to create a Twig component. ACTIVATE whenever 'trans_default_domain', 'twig component', 'translation not working', 'create twig component', or 'should I create a component' appears. Covers: trans_default_domain isolation in Twig components (1 translation = inline domain, 2+ translations = hoist trans_default_domain in the component scope), ClockInterface for dates in templates, when to create a Twig component vs use direct HTML. DO NOT use for: Twig syntax basics, Symfony controller rendering, generic CSS questions.npx claudepluginhub fabiensalles/claude-marketplace --plugin symfony