Final Class Yiisoft\Bootstrap5\CarouselItem
| Inheritance | Yiisoft\Bootstrap5\CarouselItem |
|---|
CarouselItem represents a single item within a Bootstrap Carousel widget.
Each item can contain content, caption, and caption placeholder.
The item can be set as active and supports autoplaying intervals.
- Active state: When is
true, sets this item as the first visible slide. - Auto-playing: When enabled, cycling can be paused by hovering over the carousel, focusing on it, or clicking on carousel controls/indicators.
Example usage:
`php
<?= CarouselItem::to(
'<img src="example.jpg" alt="Example">',
'Image Caption',
'Caption Placeholder'
);
?>
// Create an active carousel item with autoplay. <?= CarouselItem::to(
content: '<img src="example.jpg">',
caption: 'Slide 1',
active: true,
autoPlayingInterval: 5000
);
?>
`
Public Methods
Method Details
Sets the active state.
| public active( boolean $enabled ): self | ||
| $enabled | boolean |
Whether the breadcrumb link is active. |
| return | self |
A new instance with the specified active state. |
|---|---|---|
public function active(bool $enabled): self
{
$new = clone $this;
$new->active = $enabled;
return $new;
}
Sets the HTML attributes for the link.
| public attributes( array $attributes ): self | ||
| $attributes | array |
Attribute values indexed by attribute names. |
| return | self |
A new instance with the specified attributes. |
|---|---|---|
public function attributes(array $attributes): self
{
$new = clone $this;
$new->attributes = $attributes;
return $new;
}
Sets the autoplaying interval.
| public autoPlayingInterval( integer $interval ): self | ||
| $interval | integer |
The autoplaying interval in milliseconds. |
| return | self |
A new instance with the specified autoplaying interval. |
|---|---|---|
public function autoPlayingInterval(int $interval): self
{
$new = clone $this;
$new->autoPlayingInterval = $interval;
return $new;
}
Sets the caption content.
| public caption( string $caption ): self | ||
| $caption | string |
The caption content. |
| return | self |
A new instance with the specified caption content. |
|---|---|---|
public function caption(string $caption): self
{
$new = clone $this;
$new->caption = $caption;
return $new;
}
Sets the HTML attributes for the caption.
| public captionAttributes( array $captionAttributes ): self | ||
| $captionAttributes | array |
Attribute values indexed by attribute names. |
| return | self |
A new instance with the specified attributes for the caption. |
|---|---|---|
public function captionAttributes(array $captionAttributes): self
{
$new = clone $this;
$new->captionAttributes = $captionAttributes;
return $new;
}
Sets the caption placeholder content.
| public captionPlaceholder( string $captionPlaceholder ): self | ||
| $captionPlaceholder | string |
The caption placeholder content. |
| return | self |
A new instance with the specified caption placeholder content. |
|---|---|---|
public function captionPlaceholder(string $captionPlaceholder): self
{
$new = clone $this;
$new->captionPlaceholder = $captionPlaceholder;
return $new;
}
Sets the HTML attributes for the caption placeholder.
| public captionPlaceholderAttributes( array $captionPlaceholderAttributes ): self | ||
| $captionPlaceholderAttributes | array |
Attribute values indexed by attribute names. |
| return | self |
A new instance with the specified attributes for the caption placeholder. |
|---|---|---|
public function captionPlaceholderAttributes(array $captionPlaceholderAttributes): self
{
$new = clone $this;
$new->captionPlaceholderAttributes = $captionPlaceholderAttributes;
return $new;
}
Sets the content.
| public content( string|\Stringable $content ): self | ||
| $content | string|\Stringable |
The content. |
| return | self |
A new instance with the specified content. |
|---|---|---|
public function content(string|Stringable $content): self
{
$new = clone $this;
$new->content = $content;
return $new;
}
Sets whether to encode the caption content.
| public encodeCaption( boolean $encode ): self | ||
| $encode | boolean |
Whether to encode the caption content. |
| return | self |
A new instance with the specified encoding setting. |
|---|---|---|
public function encodeCaption(bool $encode): self
{
$new = clone $this;
$new->encodeCaption = $encode;
return $new;
}
Sets whether to encode the caption placeholder content.
| public encodeCaptionPlaceholder( boolean $encode ): self | ||
| $encode | boolean |
Whether to encode the caption placeholder content. |
| return | self |
A new instance with the specified encoding setting. |
|---|---|---|
public function encodeCaptionPlaceholder(bool $encode): self
{
$new = clone $this;
$new->encodeCaptionPlaceholder = $encode;
return $new;
}
| public getAttributes( ): array | ||
| return | array |
Returns the HTML attributes for the carousel item. |
|---|---|---|
public function getAttributes(): array
{
return $this->attributes;
}
| public getAutoPlayingInterval( ): integer|null | ||
| return | integer|null |
Returns the autoplaying interval for the carousel item. |
|---|---|---|
public function getAutoPlayingInterval(): ?int
{
return $this->autoPlayingInterval;
}
| public getCaption( ): string|null | ||
| return | string|null |
Returns the caption content for the carousel item. |
|---|---|---|
public function getCaption(): ?string
{
return $this->encodeCaption ? Html::encode($this->caption) : $this->caption;
}
| public getCaptionAttributes( ): array | ||
| return | array |
Returns the HTML attributes for the caption. |
|---|---|---|
public function getCaptionAttributes(): array
{
return $this->captionAttributes;
}
| public getCaptionPlaceholder( ): string|null | ||
| return | string|null |
Returns the caption placeholder content for the carousel item. |
|---|---|---|
public function getCaptionPlaceholder(): ?string
{
return $this->encodeCaptionPlaceholder ? Html::encode($this->captionPlaceholder) : $this->captionPlaceholder;
}
| public getCaptionPlaceholderAttributes( ): array | ||
| return | array |
Returns the HTML attributes for the caption placeholder. |
|---|---|---|
public function getCaptionPlaceholderAttributes(): array
{
return $this->captionPlaceholderAttributes;
}
| public getContent( ): string|\Stringable | ||
| return | string|\Stringable |
Returns the content for the carousel item. |
|---|---|---|
public function getContent(): string|Stringable
{
return $this->content;
}
| public isActive( ): boolean | ||
| return | boolean |
Whether the item is active. |
|---|---|---|
public function isActive(): bool
{
return $this->active;
}
Creates a new Yiisoft\Bootstrap5\CarouselItem instance.
| public static to( string|\Stringable $content = '', string|null $caption = null, string|null $captionPlaceholder = null, integer|null $autoPlayingInterval = null, boolean $active = false, boolean $encodeCaption = true, boolean $encodeCaptionPlaceholder = true, array $attributes = [], array $captionAttributes = [], array $captionPlaceholderAttributes = [] ): self | ||
| $content | string|\Stringable |
The content of the carousel item. |
| $caption | string|null |
The caption content for the carousel item. |
| $captionPlaceholder | string|null |
The caption placeholder content for the carousel item. |
| $autoPlayingInterval | integer|null |
The autoplaying interval for the carousel item. |
| $active | boolean |
Whether the item is active. |
| $encodeCaption | boolean |
Whether to encode the caption content. |
| $encodeCaptionPlaceholder | boolean |
Whether to encode the caption placeholder content. |
| $attributes | array |
The HTML attributes for the carousel item. |
| $captionAttributes | array |
The HTML attributes for the caption. |
| $captionPlaceholderAttributes | array |
The HTML attributes for the caption placeholder. |
| return | self |
A new instance with the specified configuration. |
|---|---|---|
public static function to(
string|Stringable $content = '',
?string $caption = null,
?string $captionPlaceholder = null,
?int $autoPlayingInterval = null,
bool $active = false,
bool $encodeCaption = true,
bool $encodeCaptionPlaceholder = true,
array $attributes = [],
array $captionAttributes = [],
array $captionPlaceholderAttributes = [],
): self {
return new self(
$active,
$attributes,
$autoPlayingInterval,
$caption,
$captionAttributes,
$captionPlaceholder,
$captionPlaceholderAttributes,
$content,
$encodeCaption,
$encodeCaptionPlaceholder,
);
}
Signup or Login in order to comment.