Single Directory Components
Single Directory Components (SDC) were added to Drupal 10.1 as an experimental module, and they are expected to be stable in Drupal core around 10.3.0. They are Drupal’s implementation of component-based architecture.
While experimental, the SDC module needs to be explicitly enabled. After SDC stabilizes, it will just be part of the theme system, with no separate module.
To use SDC, you’ll need to create a themename/components
directory, with a minimum of componentName.component.yml
and componentName.twig
files. You can add componentName.css
and componentName.js
as well, and they’ll be included when the component is loaded. Once the component is created, it can be included in another template using Twig’s built-in include()
function or embed
tag.
The benefit of using SDC is that relevant code is grouped, and libraries are automatically generated. In addition, it enables quick reusable components that can be moved from...