Skip to content

Commit 7930e97

Browse files
mnoconadriendupuisdabrt
authored
Documented Twig Component attribute (#2793)
* Documented Twig Component attribute * TMP * Update docs/templating/components.md Co-authored-by: Adrien Dupuis <[email protected]> * Fixes * Make the examples the same * Added highlight * Update docs/templating/components.md * Apply suggestion from @dabrt Co-authored-by: Tomasz Dąbrowski <[email protected]> --------- Co-authored-by: Adrien Dupuis <[email protected]> Co-authored-by: Tomasz Dąbrowski <[email protected]>
1 parent 14a39ce commit 7930e97

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\Twig\Component;
4+
5+
use Ibexa\Contracts\TwigComponents\Attribute\AsTwigComponent;
6+
use Ibexa\Contracts\TwigComponents\ComponentInterface;
7+
8+
#[AsTwigComponent(
9+
group: 'admin-ui-dashboard-all-tab-groups',
10+
priority: 100
11+
)]
12+
final class MyComponent implements ComponentInterface
13+
{
14+
public function render(array $parameters = []): string
15+
{
16+
return 'Hello world!';
17+
}
18+
}

docs/templating/components.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ You can create Twig Components in one of two ways:
1818

1919
### PHP code
2020

21-
Create a class implementing the `\Ibexa\Contracts\TwigComponents\ComponentInterface` interface and register it as a service by using the `ibexa.twig.component` service tag, for example:
21+
Create a class that implements the `\Ibexa\Contracts\TwigComponents\ComponentInterface` interface.
22+
Register it as a service by using the `AsTwigComponent` attribute or the `ibexa.twig.component` service tag:
2223

23-
``` yaml
24-
App\Component\MyNewComponent:
25-
tags:
26-
- { name: ibexa.twig.component, group: content-edit-form-before, priority: 0 }
27-
```
24+
=== "PHP Attribute"
25+
26+
``` php hl_lines="8-11"
27+
[[= include_file('code_samples/back_office/components/MyComponent.php', glue=' ') =]]
28+
```
29+
30+
=== "YAML configuration"
31+
32+
``` yaml
33+
App\Twig\Component\MyComponent:
34+
tags:
35+
- { name: ibexa.twig.component, group: admin-ui-dashboard-all-tab-groups, priority: 100 }
36+
```
2837

2938
The available attributes are:
3039

0 commit comments

Comments
 (0)