When creating stories, if you have multiplies stories in one *.stories.twig file like the following, then instead of each story having one template included, each story ends up getting multiple embeds.

In other words, I expect to see one button per story, but instead I see two next to each other in Storybook.

{% stories chip with {title: 'Dreamykit/Simple components/Button',} %}
  {% story default with {
    name: '1. Button',
    args: {
      type: 'button',
      input_type: '',
      text: 'button',
      href: '',
      target: '',
    }
  } %}
    {{ include('dreamykit:button') }}
  {% endstory %}
  {% story default with {
    name: '2. Link button',
    args: {
      type: 'link',
      input_type: '',
      text: 'link',
      href: '#',
      target: '_blank',
    }
  } %}
    {{ include('dreamykit:button') }}
  {% endstory %}
{% endstories %}

Issue fork storybook-3484557

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

  • 1.x Comparechanges, plain diff MR !26

Comments

droces created an issue.

droces’s picture

As a workaround, I have found that I can embed the component just once (inside one of the stories) like the following, and it will show once for each story (in other words, I see only one button in each story). However this won't work if my includes / embeds are not the same for each story, so it won't work in many cases.

{% stories chip with {title: 'Dreamykit/Simple components/Button',} %}
  {% story default with {
    name: '1. Button',
    args: {
      type: 'button',
      input_type: '',
      text: 'button',
      href: '',
      target: '',
    }
  } %}
  {% endstory %}
  {% story default with {
    name: '2. Link button',
    args: {
      type: 'link',
      input_type: '',
      text: 'link',
      href: '#',
      target: '_blank',
    }
  } %}
    {{ include('dreamykit:button') }}
  {% endstory %}
{% endstories %}
13twelve’s picture

Any update or advice here?

Being able to write multiple stories for a component is a useful feature.

13twelve’s picture

Initially I was getting around this by adding multiple `*.stories.twig` files, it seems as long as you match the `title`'s between your stories then it seems to compile and group in Storybook.

And then I tried altering the ID of the story...

```
{% story default with {
name: '1. Default',
} %}
...
{% endstory %}

{% story alt with {
name: '2. Alt',
} %}
...
{% endstory %}
```

This then allows multiple stories inside a single stories file.

So, I think this issue is actually not an issue, its just not clear how to have multiple stories (very possibly user error 🤷🏻‍♂️).

At any rate, might be worth adding to the readme to make it clearer - I'll make a MR:
https://git.drupalcode.org/project/storybook/-/merge_requests/26

cc. @droces