drupal-twig

Enforce Drupal Twig template best practices for safe, maintainable themes.

67|13|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/edutrul/drupal-ai --skill drupal-twig
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drupal-twig
Source: https://github.com/edutrul/drupal-ai/tree/main/.claude/skills/drupal-twig
Command: npx skills add https://github.com/edutrul/drupal-ai --skill drupal-twig

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Drupal theming often suffers from inconsistent Twig templates, unsafe output, and scattered best practices. This skill provides a concise, actionable guide to keep Twig templates secure, translatable, and maintainable within Drupal, including library attachment and SDC usage.

Core Features & Use Cases

  • Auto-escaping and safe output rules to prevent XSS.
  • Translation blocks using {% trans %} for all user-facing strings.
  • Attaching libraries with {{ attach_library() }} and leveraging Single Directory Components (SDC) for reusable templates.
  • Debugging support and template suggestion patterns to improve theme consistency across view modes.

Quick Start

Apply these Twig guidelines when editing Drupal templates to ensure safe, maintainable theming.

Frequently Asked Questions about drupal-twig

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

FAQPage Schema
How do I prevent XSS in Drupal Twig templates?

To prevent XSS in Drupal Twig templates, follow auto-escaping rules and avoid outputting raw variables unless explicitly marked safe. This ensures secure, maintainable themes by sanitizing user-facing output automatically.

What is the best way to handle translations in Drupal Twig theming?

The best way to handle translations in Drupal Twig theming is using the {% trans %} block for all user-facing strings. This ensures text is properly extracted and remains translatable across different languages.

How do I attach a library inside a Drupal Twig template?

You attach a library inside a Drupal Twig template using the {{ attach_library() }} function. This correctly links CSS and JS assets directly within your template files for maintainable theming.

How do I debug Drupal Twig template rendering issues?

Debug Drupal Twig template rendering by leveraging built-in debugging support and analyzing template suggestion patterns. This helps identify which template files are being loaded and improves theme consistency.

Can I use Single Directory Components for reusable Drupal templates?

Yes, you can use Single Directory Components (SDC) for reusable Drupal templates. SDC allows you to bundle Twig, CSS, and JS together, ensuring maintainable and consistent theme components across view modes.

When do I need template suggestion patterns in Drupal theming?

You need template suggestion patterns in Drupal theming when building or refactoring themes to override default rendering. They provide specific naming conventions to target content types and view modes for consistent theme displays.