Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions code_samples/back_office/components/MyComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace App\Twig\Component;

use Ibexa\Contracts\TwigComponents\Attribute\AsTwigComponent;
use Ibexa\Contracts\TwigComponents\ComponentInterface;

#[AsTwigComponent(
group: 'admin-ui-dashboard-all-tab-groups',
priority: 100
)]
final class MyComponent implements ComponentInterface
{
public function render(array $parameters = []): string
{
return 'Hello world!';
}
}
41 changes: 36 additions & 5 deletions docs/templating/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,42 @@ You can create Twig Components in one of two ways:

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:

``` yaml
App\Component\MyNewComponent:
tags:
- { name: ibexa.twig.component, group: content-edit-form-before, priority: 0 }
```
=== "PHP Attribute2"

``` php
[[= include_file('code_samples/back_office/components/MyComponent.php') =]]
```

=== "PHP Attribute"

``` php
<?php declare(strict_types=1);

namespace App\Twig\Component;

use Ibexa\Contracts\TwigComponents\Attribute\AsTwigComponent;
use Ibexa\Contracts\TwigComponents\ComponentInterface;

#[AsTwigComponent(
group: 'admin-ui-dashboard-all-tab-groups',
priority: 100
)]
final class MyComponent implements ComponentInterface
{
public function render(array $parameters = []): string
{
return 'Hello world!';
}
}
```

=== "YAML configuration"

``` yaml
App\Component\MyNewComponent:
tags:
- { name: ibexa.twig.component, group: content-edit-form-before, priority: 0 }
```

The available attributes are:

Expand Down
Loading