Composition
Given this component:
<?php
namespace App\Component;
final readonly class Greeter
{
public function __construct(
public string $name,
) {}
} ?>
<template>
<span>Hello, {{ $this->name }}!</span>
</template>
In order to use it in another component template, you have to import it using the :uses
attribute on the
<template>
tag first.
All the required Greeter
component constructor arguments must be set using computed attributes. The order does
not matter given that Sapin will invoke the constructor with the named argument syntax.
the :uses
attribute may contains multiple imports. They must be coma separated. Trailing comas are allowed.
These following examples are valid:
An import can be aliased following the same syntax as php: