Re is out: see what's new Lifetime updates on every purchase Support replies within 24 hours Secure checkout via Gumroad 8,500+ sales since 2016

↑↓ Navigate ↵ Open Esc Close

All products
Re:Maily contact form builder is now available on WordPress.org See it live

Layout types

Updated 2 min read 16 views

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 ) => '',
];
KeyWhat it does
settingsThe 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
fieldsChanges 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_classesClasses for the item at a position; here every fifth item is wide
cssMore 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?