Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

storybook

4,292 sites Security covered
View on drupal.org

✨ The integration between Drupal and Storybook

The Storybook Drupal module enhances the Twig templating language by introducing two new Twig tags: stories and story, so you can write Storybook stories in Twig. With this module, you can easily create and manage Storybook stories directly in your Twig templates, making it a powerful tool for documenting and showcasing your frontend templates.

📖 Read the article about the module


Watch the video tutorial

5 min 📹 The full set up on both apps, Drupal and Storybook


Watch the video tutorial

5 min 📹 Single Directory Components and Storybook.

This module lets you put any arbitrary Twig into your Storybook stories. You don't need Single Directory Components to integrate with Storybook (they work as well, but they are not required).

Creating Stories

Once the Twig Storybook extension is registered, you can start creating stories within your Twig templates. We recommend writing the stories in a file with name file-name.stories.twig.

  • Use the {% stories %} tag to define a group of stories.
  • Use the {% story %} tag to define an individual story.

Here's an example:

{# some/path/in/your/code/base/my-card.stories.twig #}
{% stories my_card with { title: 'Components/Examples/Card' } %}

  {% story default with {
    name: '1. Default',
    args: { cardHeader: 'I am a header!', buttonText: 'Learn more', buttonIconType: 'power' }
  } %}
    {# Write any Twig for the "default" story. The `args` above will be #}
    {# made available as variables for the template 👇 #}
    {% embed '../examples/my-card.html.twig' with { header: cardHeader } %}
      {% block card_body %}
        <p>I am the <em>card</em> contents.</p>
        {# You can use *any* valid Twig here, including SDCs #}
        {{ include('my-theme:my-button', { text: buttonText, iconType: buttonIconType }) }}
      {% endblock %}
    {% endembed %}
  {% endstory %}

{% endstories %}

This will render as:

Drupal setup

In development.services.yml you want to add some configuration for Twig, so you don't need to clear caches so often, and to enable development mode.

You also need to enable CORS, so the Storybook application can talk to your Drupal site. You want this CORS configuration to be in development.services.yml so it does not get changed in your production environment.

Remember

Make sure to grant permission to Render Storybook stories for anonymous users. Keep this permission disabled in production.

drush role:perm:add anonymous 'render storybook stories'

The configuration you want looks like this:

parameters:
  # ...
  # Remember to disable development mode in production!
  storybook.development: true
  cors.config:
    enabled: true
    allowedHeaders: ['*']
    allowedMethods: ['*']
    allowedOrigins: ['*']
    exposedHeaders: false
    maxAge: false
    supportsCredentials: true
services:
  # ...

Disable render cache and twig cache:

drush state:set twig_debug 1
drush state:set twig_cache_disable 1
drush state:set disable_rendered_output_cache_bins 1

Storybook setup

Are you using ddev?

No necessary extra steps are required, but check out this section in the README.md for some optional improvements.

Install Storybook as usual:

# Make use of modern versions of yarn.
yarn set version berry
# Avoid pnp.
echo 'nodeLinker: node-modules' >> .yarnrc.yml
# Install and configure stock Storybook.
yarn dlx sb init --builder webpack5 --type server

Then update .storybook/main.js to scan for JSON stories where your application stores them.

Troubleshooting

If you use a self-signed certificate in your local, for instance using ddev, you will need to accept the browser exception for Storybook to work. Open the Drupal site in your browser, and accept the exception. Then Storybook should work.

Compiling Twig stories into JSON

The Storybook application will does not understand stories in Twig format. It will fail to render them. You need to compile them into a *.stories.json. To do so you can run:

drush storybook:generate-all-stories

If you want to monitor story changes to compile Twig stories into JSON, execute it with watch. Like so:

watch --color drush storybook:generate-all-stories

Are you using macOS?

In this case the watch command may not be installed. Use homebrew to install it.

brew install watch

Activity

Total releases
1
First release
Mar 2026
Latest release
1 month ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.0.3 Stable Mar 17, 2026