# CarouselItem

> Represents a Carousel slide: a .carousel-item element with its content.

[API reference](/docs/api/index.md) › [Bootstrap 6](/docs/extensions/bootstrap6/reference/index.md) › [item](/docs/extensions/bootstrap6/reference/item/index.md) › CarouselItem

| final readonly class | `yii2\extensions\bootstrap6\item\CarouselItem` |
| --- | --- |
| Uses traits | [`ItemTrait`](/docs/extensions/bootstrap6/reference/item/itemtrait/index.md) |
| Source | [`src/item/CarouselItem.php`](https://github.com/yii2-extensions/bootstrap6/blob/main/src/item/CarouselItem.php#L14) |

Represents a `Carousel` slide: a `.carousel-item` element with its content.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-content"></span>`$content` readonly constructor | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Content of the slide (not encoded). | `CarouselItem` |
| <span id="property-options"></span>`$options` readonly constructor | `array<array-key, mixed>` | HTML attributes of the `.carousel-item` element. Default: `[]`. | `CarouselItem` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`fromArray()`](#method-fromArray) static | Creates a slide from the array configuration documented in `Carousel::$items`. | `CarouselItem` |
| [`to()`](#method-to) static | Creates a slide. | `CarouselItem` |
| [`withContent()`](#method-withContent) | Returns a copy with the given content. | `CarouselItem` |
| [`withOptions()`](#method-withOptions) | Returns a copy with the given `.carousel-item` attributes. | `CarouselItem` |

## Method details

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

```php
public static function fromArray(array<array-key, mixed> $config): self
```

Creates a slide from the array configuration documented in `Carousel::$items`.

An `options` key that is not an array is ignored.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `array<array-key, mixed>` | Slide configuration. |

**Returns**

`self`

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the slide has no `string|Stringable` `content`.

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

```php
public static function to(string|Stringable $content): self
```

Creates a slide.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Content of the slide (not encoded). |

**Returns**

`self`

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

```php
public function withContent(string|Stringable $content): self
```

Returns a copy with the given content.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) |  |

**Returns**

`self`

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

```php
public function withOptions(array<array-key, mixed> $options): self
```

Returns a copy with the given `.carousel-item` attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$options` | `array<array-key, mixed>` | HTML attributes of the `.carousel-item` element. |

**Returns**

`self`