Intro to Drupal Theming

Theming changes the look and feel of a site.

Themes

A theme is where you customize html and css, and can include javascript for making things dynamic.

Without any themeing, all Drupal components will have default templates. This lets you override the parts you want and keep the defaults as needed.

Twig Templates

Drupal uses twig templates, which is a powerful templating language.

Learn more about twig: https://www.drupal.org/docs/theming-drupal/twig-in-drupal

Template Overrides

Drupal Core components have templates provided by the modules that define them.

For example, fields use /core/modules/system/templates/field.twig.html.

You can customize these templates by copying them to your theme directory.

Twig Debugging

Turn on twig debugging to output template suggestions above each component in your html.

https://www.drupal.org/docs/theming-drupal/twig-in-drupal/debugging-twi…

Libraries

CSS and Javascript are defined as libraries. Some will be loaded globally, and some will be added per component.

Theme Hooks

In your .theme file, define new components with hook_theme().

Preprocessing

Massage the values fetched from the database before they are passed to template components.

Level
Topics