On this page
API for Single-Directory Components
Last updated on
27 March 2025
The API of Single-Directory Components includes:
- The component plugin manager: the
plugin.manager.sdc
service is implemented inDrupal\Core\Theme\ComponentPluginManager
by default. This service is needed by modules that need to find and instantiate components. - Various component-related exceptions listed in
core/lib/Drupal/Core/Render/Component/Exception
. Code using Single-Directory Components can rely and extend these exceptions. - The folder structure of a component and the naming conventions of the files in it.
- The structure of the component metadata (the
my-component.component.yml
). Note that the metadata of the component is described, and optionally validated, by the schema inmetadata.schema.json
(this file is for internal validation and not part of the API). - The render element and its class
\Drupal\Core\Render\Element\ComponentElement.
- The naming convention for the ID when using Twig's
include
andembed
fucntions. This naming convention is[module-or-theme-machine-name]:[component-machine-name]
. See the example below.
{{ include('sdc_examples:my-button', { text: 'Click Me', iconType: 'external' }, with_context = false) }}
This way of specifying the component for Twig's include
and embed
function ('my-theme:my-component'
in the example) will not change, as it is considered an API.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion