Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

Styles API

2,789 sites Security covered
View on drupal.org

This module provides a central repository for theme templates, allowing themes to register their templates in YAML files instead of code. This makes theme definitions more organized and accessible for other modules to interact with. It also allows for the addition of administrative elements like labels, icons, and descriptions to these theme definitions.

This module allows other modules or themes to register theme templates on a YAML file (replacing hook_theme()) and provide a repository for all themes registered.

This will give more order to theme definitions, taking them away form code.

But moreover in this way themes and modules could gather information of registered themes implementation.

For example a module could alter block form to add select field to forms, providing a UI to easily assign predefined templates for elements, blocks or regions.

Among standard hook_theme() settings, the definition will add Admin UI elements like labels, icons, categories, descriptions.

Declaring themes

Themes must be registered on a *.themes.yml file with the following format:

block__clean:
  label: Clean Wrapper
  type: block
  category: Block
  configuration:
    path: templates/clean
    base hook: block
    render element: elements

The id of the theme will name the template as in hook_theme().
Path is relative to the module or template, base path eill be added for proper rendering.

Basic functions

Style::stylePluginManager()->getDefinitions() will return all themes declared.

Projects using Styles API

We hope this module will be merged into core: Declare themes on YAML file as an alternative to hook_theme

Activity

Total releases
1
First release
Jan 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Release date
8.x-1.3 Stable Jan 22, 2025