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

Supporting organizations: 

Project information

Releases