Theming

Add a Twig Template to Your Single Directory Component for Drupal 10, 11

Last updated
Categories
Up-to-date with minor version
11.0.x

Drupal single directory components use Twig template files to define their HTML markup and how the values of props and slots are displayed. To discover available props and slots, read the component’s .component.yml file. When working with slots, you’ll often choose between rendering a slot as a Twig block ({% block %}) or interpolating a variable directly ({{ variable }}).

In this tutorial, you’ll:

  • Add a card.twig file to an existing component directory.
  • Read the associated card.component.yml schema to identify props and slots you can work with.
  • Render props and slots wrapped in custom HTML markup.

By the end of this tutorial, you’ll be able to connect a Twig template to any SDC and render the props and slots passed into the component.

Frontend Theming