Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Styles API

Security covered Under active development 3,606 sites

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

Drupal 8–11

Ask your assistant about Styles API

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

1 tracked project depends on this one

Activity

Tracked releases
2
Tracked since
Jan 2023
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Active

Releases

Version Type Core PHP Release date
8.x-1.3 Stable 8–11 Jan 22, 2025
8.x-1.2 Stable 8–10 Jan 20, 2023