Skip to content

Commit 72301cd

Browse files
committed
Update README
1 parent 7d2a8e2 commit 72301cd

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class ScriptNonceSubscriber implements EventSubscriberInterface
204204
### stimulus_controller
205205

206206
This bundle also ships with a special `stimulus_controller()` Twig function
207-
that can be used to render [Stimulus Controllers & Values](https://stimulus.hotwired.dev/reference/values)
207+
that can be used to render [Stimulus Controllers & Values](https://stimulus.hotwired.dev/reference/values), [Outlets](https://stimulus.hotwired.dev/reference/outlets)
208208
and [CSS Classes](https://stimulus.hotwired.dev/reference/css-classes).
209209
See [stimulus-bridge](https://github.com/symfony/stimulus-bridge) for more details.
210210

@@ -260,6 +260,17 @@ If you have multiple controllers on the same element, you can chain them as ther
260260
</div>
261261
```
262262

263+
If you need to attach an outlet to some controller, you can call the addOutlet() method.
264+
265+
For example:
266+
267+
```twig
268+
<div {{ stimulus_controller('foo').addOutlet('bar', '.bar') }}>Hello</div>
269+
270+
<!-- would render -->
271+
<div data-controller="foo" data-foo-bar-outlet=".bar">Hello</div>
272+
```
273+
263274
You can also retrieve the generated attributes as an array, which can be helpful e.g. for forms:
264275

265276
```twig

src/Dto/StimulusControllersDto.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function addOutlet(string $outletName, string $selector)
5151

5252
$this->outlets['data-'.$this->controllers[0].'-'.$outletName.'-outlet'] = $selector;
5353

54-
return new Markup($this, 'UTF-8');
54+
return $this;
5555
}
5656

5757
public function __toString(): string
@@ -61,15 +61,15 @@ public function __toString(): string
6161
}
6262

6363
return rtrim(
64-
'data-controller="'.implode(' ', $this->controllers).'" '.
64+
'data-controller='.implode(' ', $this->controllers).
6565
implode(' ', array_map(function (string $attribute, string $value): string {
6666
return $attribute.'="'.$this->escapeAsHtmlAttr($value).'"';
6767
}, array_keys($this->values), $this->values)).' '.
6868
implode(' ', array_map(function (string $attribute, string $value): string {
6969
return $attribute.'="'.$this->escapeAsHtmlAttr($value).'"';
7070
}, array_keys($this->classes), $this->classes)).' '.
7171
implode(' ', array_map(function (string $attribute, string $value): string {
72-
return $attribute.'="'.$this->escapeAsHtmlAttr($value).'"';
72+
return $attribute.'='.$this->escapeAsHtmlAttr($value);
7373
}, array_keys($this->outlets), $this->outlets))
7474
);
7575
}

0 commit comments

Comments
 (0)