Carousel

A tile-based horizontal scroll carousel with CSS scroll-snap, prev/next navigation buttons, and optional dot indicators. Each click of Next/Prev snaps to the adjacent tile. Supports server-rendered tiles (PHP array) or client-side loading from a remote JSON endpoint.

Dot placement defaults to 'below'. Use ->dots('above') or ->dots('none') to change or remove them.

Default — dots below

Server-rendered tiles, dot indicators positioned below the carousel.

PHP

Dots above

Navigate with dots placed above the carousel. Use a wider tile width.

PHP

No dots

Carousel with only prev/next buttons — no dot indicators.

PHP

Single tile — buttons / dots hidden

When only one tile exists, navigation buttons and dots are automatically hidden.

PHP

Tiles without images

When no imageUrl is provided, a placeholder icon is shown.

PHP

Remote datasource (client-side)

Pass ->remoteUrl() instead of ->tiles() to load tiles client-side on page load. The endpoint should return { "tiles": [ {title, href, imageUrl, caption}, … ] }. A perPage query param is appended when set via ->perPage().

Tiles load automatically from /demo/carouselData on page load.
PHP

Tiles with chips

Pass an optional chip (and optional chipVariant) per tile to show a coloured chip label overlaid in the top-right corner of the tile image. Variants: primary, success, warning, danger, purple, secondary (default), info.

PHP

JS API

Control the carousel programmatically using m.carousel(id).

Current tile: —

PHP PHP Methods (Fluent)

Method / PropertyParametersDescription
$m->carousel($id)stringCreate a Carousel component.
->tile($title, $href, $imageUrl, $caption, $chip, $chipVariant)string, string, ?string, ?string, ?string, stringAdd a single tile. imageUrl, caption, and chip are optional. chipVariant defaults to 'secondary'.
->tiles($tiles)arrayAdd multiple tiles at once. Each element: {title, href, imageUrl?, caption?, chip?, chipVariant?}.
->remoteUrl($url)stringClient-side remote datasource URL. Response: {"tiles":[…]}. Each tile object may include chip and chipVariant.
->perPage($n)intTiles per remote fetch (appended as ?perPage=N). Default: 0 (load all).
->dots($placement)stringDot indicator placement. 'below' (default), 'above', or 'none'.
->tileWidth($css)stringCSS width of each tile. Default: '160px'. Accepts any CSS length.
->tileGap($px)intGap between tiles in pixels. Default: 12.

JS JS Methods

Method / PropertyParametersDescription
m.carousel(id)string|ElementGet the Carousel API for the given element ID or DOM element.
c.goTo(idx)numberNavigate to tile at zero-based idx.
c.next()Navigate to the next tile.
c.prev()Navigate to the previous tile.
c.current()Returns the current tile index (0-based).
c.count()Returns the total number of tiles.
c.reload(url?, perPage?)Reload tiles from a remote URL. Defaults to configured remoteUrl/perPage.

EVENT Events

Event NameDetailDescription
m:carousel:change{ index: number }Fired on the carousel element when the active tile changes.
m:carousel:loaded{ count: number }Fired on the carousel element after remote tiles have loaded.