Skip to content

Documented Twig Component attribute #2793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 15, 2025
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