- Date:
- Author:
- Salsa Digital
The main focus for this month’s Melbourne Drupal Meetup was a presentation by Amey Mudras on single directory components (SDCs). Amey introduced SDCs and explained how they streamline the theming process in Drupal.
Introduction to single directory components (SDC): presentation summary
This presentation introduced the concept of Single Directory Components (SDC) in Drupal. Amey explained that SDC is designed to address long-standing challenges in the Drupal theming layer, such as the scattered nature of templates, stylesheets, and assets. Traditionally, finding and managing these files has been difficult, particularly as themes grow more complex.
Amey highlighted that Drupal themers have faced multiple entry points for altering business logic, such as modifying a button’s layout. This lack of a unified structure has made maintaining and scaling the codebase challenging, especially as the theme evolves over time.
Benefits of SDC
SDC aims to streamline the theming process by grouping all files related to a specific component—Twig templates, CSS, and JavaScript—into a single directory. This new approach offers several significant benefits:
-
Improved organisation: Grouping all necessary files for a component in one directory simplifies the maintenance of the codebase. Developers can easily locate and manage component-specific files without searching through multiple directories.
-
Automatic library creation: SDC handles the creation and scoping of CSS and JS files automatically. Unlike the traditional method, where developers had to define and attach libraries manually, SDC reduces these steps by automatically including and scoping the necessary files.
-
Reusability and consistency: Components created using SDC are modular and reusable across different projects or themes, ensuring consistency in design and functionality across a Drupal site. This modularity simplifies maintaining a consistent look and feel.
-
Scalability and collaboration: SDC enhances scalability by allowing developers to test components in isolation before integrating them into a larger project. This approach also facilitates better collaboration among teams working on large-scale projects.
Implementation and practical use
Amey provided a practical demonstration of implementing SDCs in Drupal. He showed how to create a simple button component within a theme, explaining that all necessary files—Twig, component.yml, CSS, and JS—are housed in a single directory. The component.yml file defines the component, specifying properties such as the component’s name and required arguments.
He also introduced the Component Library Generator module, which automates the creation of SDCs. By using a Drush command, developers can generate the necessary files and directory structure for a new component, making it easier to get started with SDCs.
Amey discussed how SDCs can be overridden in child themes, allowing for customisation without altering the original files in the parent theme. By copying the necessary files to the child theme, developers can make changes specific to the child theme while retaining the original functionality.
Looking forward, Amey noted the potential for SDCs to integrate with tools like the SDC Server and Storybook, enabling developers to create comprehensive design systems. These tools would allow for a visual library of components, making it easier to manage and reuse components across different projects.
In conclusion, Amey emphasised that while SDCs are currently an experimental module in Drupal 10.1.x, they represent a significant improvement in Drupal theming. SDCs offer a more structured, scalable, and maintainable approach to theming, making them a valuable tool for Drupal developers.