Layout types
A theme can add a layout type next to Grid, Masonry and the others. It takes two steps.
1. Register it
add_filter( 'forma_layouts_styles', fn( $types ) => $types + [ 'carousel' => 'Carousel' ] );
2. Describe it in layout.php
Put its files in your-theme/forma/layouts/carousel/. layout.php has Name: and Description: headers and returns the type’s definition:
<?php
/**
* Name: Carousel
* Description: Items in one row that scrolls sideways.
*/
return [
'settings' => [
'row_height' => [ 'type' => 'number', 'label' => 'Row height', 'default' => 240, 'min' => 80, 'max' => 600, 'unit' => 'px', 'responsive' => true ],
'captions' => [ 'type' => 'toggle', 'label' => 'Captions', 'default' => true ],
],
'fields' => [
'columns' => false,
'gap_y' => [ 'disabled' => true ],
'gap_x' => [ 'label' => 'Spacing', 'max' => 100 ],
],
'item_classes' => fn( $index, $config ) => 0 === $index % 5 ? [ 'is-wide' ] : [],
'css' => fn( $config, $scope, $breakpoints ) => '',
];
| Key | What it does |
|---|---|
settings | The type’s own fields, of the types number, select, toggle and text. Each is a CSS variable on the grid, --forma-{key} (here --forma-row-height: 240px; a toggle is 1 or 0), set per device when it is responsive |
fields | Changes to the shared Columns & gaps fields columns, gap_x and gap_y: false hides one, an array sets its label, help, min, max or disabled |
item_classes | Classes for the item at a position; here every fifth item is wide |
css | More CSS for the grid; $scope is the grid’s selector |
Style and script
A style.css and a script.js next to layout.php load on pages that show this type. The script finds the type’s settings in the grid’s data-forma attribute, under layoutSettings, and in the detail of every JavaScript event.
Was this article helpful?
Thanks for your feedback!