Aller au contenu principal
Version: 0.4.0

Component

Permet d'ajouter du code métier lié à un composant Twig.

remarque

Un composant Twig, est un template Twig appelé par la fonction component dans un template Twig.

Exemple

Dans cet exemple, un viens appelé le composant article-card.

base.html.twig
{{ component('blog/article-card') }}

Dans un controller, je peux utiliser l'attribut Component pour greffer une logique métier lié à ce composant.

MyController.php
#[Component('blog/article-card')]
public function articleCard():array
{
    $title = "Mon titre";
    $content = "Mon contenu";

    return compact('title', 'content');
}

:::warning
La méthode doit retourner un tableau associatif.
:::

```twig title="blog/article-card.html.twig"
{{ title }}
{{ content }}
```