Summary of "Getting Started with Twig Templates in Drupal CMS"

Getting Started with Twig Templates in Drupal CMS

Core message

Tip: Twig auto-escapes output by default — avoid using |raw unless you fully trust the content.

Key concepts and syntax

Basic Twig syntax

Example:

{% for item in items %}
  {{ item.title|trim }}
{% endfor %}

Escaping and raw

Drupal-specific templating concepts

Template hierarchy / suggestions

Variables and render arrays

Attributes and classes

Debugging Twig in Drupal

Template reuse and extension patterns

Example:

{% extends 'base.html.twig' %}

{% block content %}
  {{ parent() }}
  <p>Additional content</p>
{% endblock %}

Overriding templates in a theme or subtheme (common workflow)

  1. Turn on Twig debugging and disable caching: Admin → Configuration → Development → Development settings.
  2. Inspect the page and read the theme debug comments to find the correct template suggestion(s).
  3. Copy the core/contrib template file (e.g., core/themes/.../templates/node.html.twig or html.html.twig) into your theme’s templates/ directory (keep proper folder structure as needed).
  4. Clear caches: drush cr and verify the debug comment now points to the theme’s template.
  5. Modify the template in the theme. Use small blocks or includes where appropriate for reusability.
  6. If you need to add classes or computed values site-wide, implement theme preprocess functions in PHP (e.g., theme_preprocess_node) and add data to the variables array so Twig receives simpler variables.

Useful contributed modules & tools

Tools mentioned: PHPStorm, OBS, Ream, TikTok.

Practical code and commands

Common pitfalls & advice

Resources recommended

Speakers / sources referenced

Category ?

Educational


Share this summary


Is the summary off?

If you think the summary is inaccurate, you can reprocess it with the latest model.

Video