# MessageTemplate

> Formats the sprintf template held by the backing value of a message enum case.

[API reference](/docs/api/index.md) › [Scaffold](/docs/extensions/scaffold/reference/index.md) › MessageTemplate

| trait | `PHPForge\Scaffold\MessageTemplate` |
| --- | --- |
| Source | [`src/MessageTemplate.php`](https://github.com/php-forge/scaffold/blob/main/src/MessageTemplate.php#L12) |

Used by 2 types:

- [`PHPForge\Scaffold\Console\Message`](/docs/extensions/scaffold/reference/console/message/index.md)
- [`PHPForge\Scaffold\Exception\Message`](/docs/extensions/scaffold/reference/exception/message/index.md)

Formats the `sprintf` template held by the backing value of a message enum case.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`getMessage()`](#method-getMessage) | Returns the message template formatted with `$argument`. | `MessageTemplate` |
| [`plural()`](#method-plural) static | Returns the text of `$one` when `$count` is `1`, and the text of `$many` otherwise. | `MessageTemplate` |

## Method details

### getMessage() <span id="method-getMessage"></span>

```php
public function getMessage(int|string ...$argument): string
```

Returns the message template formatted with `$argument`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `...$argument` | `int\|string` | Values substituted into the template. |

**Returns**

`string`: Formatted message.

### plural() <span id="method-plural"></span>

```php
public static function plural(int $count, self $one, self $many): string
```

Returns the text of `$one` when `$count` is `1`, and the text of `$many` otherwise.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$count` | `int` | Number of items the fragment counts. |
| `$one` | `self` | Fragment for a single item. |
| `$many` | `self` | Fragment for zero or several items. |

**Returns**

`string`: Text of the fragment that agrees with `$count`.