Drupal Theming: Install, Source and Security | FunnelSlayer

Drupal Theming

Published by thomasroger76 in drupal-skills

No known issues3 installs

What this skill does

Use when creating or customizing Drupal themes, writing Twig templates, implementing preprocess hooks in .theme files, declaring CSS/JS libraries (.libraries.yml), configuring responsive images with breakpoints.yml, debugging template suggestions via Twig debug, overriding base themes, building with Bootstrap5 sub-theme, compiling SCSS with Gulp/Webpack/Vite, implementing BEM methodology with Storybook component documentation, using CSS Container Queries or Cascade Layers, creating Single Direct

Add Drupal Theming to your agent

Review the source and files first. When you are ready, copy the prompt instruction or use the CLI command supported by your environment.

Install with a prompt

Paste this into a compatible coding agent:

add this skill "drupal-theming" from https://github.com/thomasroger76/drupal-skills

Install with the CLI

Run this command in a controlled environment after reviewing the repository:

npx skills add https://github.com/thomasroger76/drupal-skills --skill drupal-theming

Skill instructions

Drupal Theming — Architecture & Référence Complète

Overview

Référentiel complet du theming Drupal 8-11+ : anatomie d'un thème, gestion des assets, moteur Twig, suggestions de templates, preprocess PHP, images responsives. Absorbe drupal-frontend.

Pattern dominant agences françaises : Bootstrap 5 via drupal/bootstrap5 avec sous-thème custom (80%+ des projets). Le fichier bootstrap5.md couvre la création complète d'un sous-thème Bootstrap 5 avec SCSS, templates Twig Bootstrap, menus responsive, carrousels Paragraphs, et formulaires avec classes BS5.

Quick Decision Table

BesoinOutilRéférence
Créer un thème from scratchStructure + .info.ymltheme-anatomy.md
Définir des régionsregions: dans .info.ymltheme-anatomy.md
Choisir / hériter d'un base themebase theme: — stable9 / olivero / falsetheme-anatomy.md
Charger CSS/JS sur toutes les pageslibraries: dans .info.ymllibraries-assets.md
Charger CSS/JS conditionnellement en Twig{{ attach_library('mon_theme/lib') }}libraries-assets.md
Charger CSS/JS depuis PHP (preprocess)$variables['#attached']['library'][]libraries-assets.md
Remplacer une librairie core/contriblibraries-override: dans .info.ymllibraries-assets.md
Étendre une librairie existantelibraries-extend: dans .info.ymllibraries-assets.md
Passer des données PHP → JavaScriptdrupalSettingslibraries-assets.md
JS sans jQuery (D9+)core/once + vanilla JSlibraries-assets.md
Savoir quel template modifierTwig Debug — commentaires HTMLtheme-suggestions.md
Surcharger le template d'un nœudnode--TYPE--VIEW-MODE.html.twigtheme-suggestions.md
Ajouter une suggestion conditionnellehook_theme_suggestions_HOOK_alter()theme-suggestions.md
Accéder proprement aux valeurs de champs en TwigModule twig_field_value — field.value, field.0.valuetwig-templates.md
Exclure un champ du rendu{{ content|without('field_image') }}twig-templates.md
Ajouter une classe CSS dynamique{{ attributes.addClass('ma-classe') }}twig-templates.md
Filtres Drupal (t,render,
Préparer des variables avant Twighook_preprocess_HOOK dans .themepreprocess.md
Classes CSS dynamiques selon contextePreprocess + $variables['attributes']preprocess.md
Images responsive multi-breakpointbreakpoints.yml + Responsive Image Stylesresponsive-images.md
WebP automatiqueImage Styles D10+responsive-images.md
Supprimer CSS core/contribstylesheets-remove: / hook_css_alterlibraries-assets.md
Modifier librairies d'autres moduleshook_library_info_alterpreprocess.md
Ajouter meta tags / preconnecthook_page_attachments_alterpreprocess.md
Créer un composant réutilisable (D10.3+)Single Directory Componentstheme-anatomy.md
Utiliser Bootstrap 5 comme basedrupal/bootstrap5 + sous-thème custombootstrap5.md
Créer un sous-thème Bootstrap 5.info.yml avec base theme: bootstrap5bootstrap5.md
Surcharger des templates Bootstrap5Copier dans templates/ du sous-thèmebootstrap5.md
Générer un thème Drupal 11 complet from scratchAgent /drupal-generate-themeagents/theme-generator.md
Générer un thème via le starterkit core officielphp core/scripts/drupal generate-themeagents/theme-generator.md
Compiler SCSS → CSS (nouveaux projets)Vite (recommandé 2025+)build-pipeline.md
Compiler SCSS → CSS (projets legacy)Gulp ou Webpackbuild-pipeline.md
Service Docker Node.js pour le thèmenode:22-alpine + npm run watchbuild-pipeline.md
Twig 3 arrow functions (|map, |filter, |reduce)Arrow functions u => u.nametwig3-accessibility.md
Navigation accessible avec ARIAaria-current, aria-expandedtwig3-accessibility.md
Images avec alt WCAGalt="" décoratif, alt descriptiftwig3-accessibility.md
Template email HTML (Symfony Mailer)CSS inline, structure HTML emailemail-templates.md
apply block Twig 3{% apply upper %}{% endapply %}twig3-accessibility.md
Nommer les classes CSS selon BEM.block__element--modifier dans Twigbem-storybook.md
CSS responsive selon le conteneur (pas la viewport)CSS Container Queriescss-moderne.md
Dark mode auto (prefers-color-scheme)CSS Variables + @media darkcss-moderne.md
CSS adapté RTL/LTR automatiquementCSS Logical Propertiescss-moderne.md
Organiser CSS avec priorités explicitesCSS Cascade Layers @layercss-moderne.md
Documenter et tester les composants visuellementStorybook + HTML storiesbem-storybook.md
Service Docker pour Storybooknode:22-alpine port 6006bem-storybook.md
État CSS via BEM modifier.card--active vs .is-activebem-storybook.md
Accessibilité WCAG 2.1 AA (ARIA, keyboard, contrast)alt text obligatoire, focus visible, landmarksaccessibility.md
Screen reader — contenu visible uniquement.visually-hidden + aria-live pour les annoncesaccessibility.md
Tester l'accessibilité automatiquementaxe-core, Lighthouse, editoria11y moduleaccessibility.md
Skip link — navigation clavier rapidePremier élément de page = <a href="#main-content">accessibility.md

Anti-Patterns Critiques

❌ À ne jamais faire✅ Bonne pratiqueRaison
class="{{ attributes.class }} ma-classe"{{ attributes.addClass('ma-classe') }}Écrase les classes Drupal système
core/jquery en dépendance par défautcore/once + vanilla JSjQuery n'est plus chargé par défaut D9+
jQuery(document).ready(function() {})(function(Drupal, once) { Drupal.behaviors.X = {...} })(Drupal, once)Pattern Drupal behaviors obligatoire
Logique complexe dans les templates TwigDéplacer dans preprocess_HOOKTwig doit rester déclaratif
base theme: classy en D10+base theme: stable9 ou base theme: falseclassy supprimé en D10
{{ node.field_image.value }}{{ content.field_image }} ou {{ node.field_image.entity.uri.value }}content applique le formatter, node donne le raw
!important dans CSSComprendre la cascade, utiliser les niveaux CSSIndique une mauvaise architecture CSS
Charger toutes les librairies globalementAttacher conditionnellementPerfs — Drupal charge à la demande
$variables['theme_hook_suggestions'][]hook_theme_suggestions_HOOK_alter()Ancienne API, toujours fonctionnelle mais déconseillée

Évolution par Version Majeure

FeatureD8D9D10D11
jQuery chargé par défaut✅⚠️ opt-in❌❌
Base theme classy✅✅❌ supprimé❌
Base theme stable9❌✅✅ recommandé✅
Base theme olivero (front)❌❌✅ stable✅
Base theme claro (admin)❌✅ stable✅✅
core/once (remplace jQuery once)❌✅✅ standard✅
WebP natif (Image Styles)❌❌✅✅
Single Directory Components (SDC)❌❌✅ expérimental✅ stable
{% trans %} / {% plural %} Twig✅✅✅✅

Auto-Amélioration

  • lessons.md — Bugs trouvés en usage réel. Ajouter une entrée après chaque correction.
  • CHANGELOG.md — Historique des versions (v1.3 courante).

See Also

  • drupal-core — hooks, services, rendering system côté module, TrustedCallbackInterface pour les callbacks #pre_render
  • drupal-config — Config Management (config/install du thème)
  • drupal-security — échappement XSS dans Twig, #markup vs #plain_text
  • drupal-deployment — drush cr, drush twig:debug, cache rebuild
  • drupal-docker — Service Node.js Docker Compose pour le build pipeline
  • drupal-performance — agrégation CSS/JS, WebP, Core Web Vitals, lazy loading images
  • drupal-content-modeling — templates Paragraphs, Layout Builder, nodes, Block Content types
  • drupal-sdc — Single Directory Components, Storybook, props et slots
  • drupal-gin — Admin theme Gin pour personnaliser l'interface d'administration

Files included

  • accessibility.md
  • agents/theme-generator.md
  • bem-storybook.md
  • bootstrap5.md
  • build-pipeline.md
  • CHANGELOG.md
  • css-moderne.md
  • email-templates.md
  • lessons.md
  • libraries-assets.md
  • preprocess.md
  • README.md
  • responsive-images.md
  • SKILL.md
  • theme-anatomy.md
  • theme-suggestions.md
  • twig-templates.md
  • twig3-accessibility.md

More skills