Write a custom SLB section: schema reference and example
A section is a PHP file with a @section JSON schema in a plain comment at the top. Put it in your theme’s sections/ folder and SLB picks it up and merges it with the starter sections; a theme section wins when the slug is the same.
The header
The schema JSON sits after @section inside a plain /* */ comment, and fields are listed under settings:
<?php
/*
@section
{
"name": "FAQ",
"category": "content",
"settings": [
{ "id": "headline", "type": "text", "label": "Headline", "default": "Frequently Asked Questions" }
]
}
*/
Schema keys
| Key | What it does |
|---|---|
name, category |
Label and group in the Add Section picker. |
settings |
The fields editors can change. |
blocks |
Repeatable typed child blocks, such as FAQ items or feature cards. |
default_blocks |
Blocks a new instance starts with. |
max_blocks |
Upper limit on blocks in one instance. |
presets |
Named, pre-configured starting points for a section. |
max_per_page |
Limits how many instances of a section a page can have. |
heading_level |
The heading tag the section uses, for example h2. |
visible_if |
On a field: show it only when another field has a given value (operators eq, neq, in). |
Fields also accept validation rules: required, min_length, max_length, min and max. See field types.
Worked example: a trimmed FAQ section
This is trimmed from the FAQ starter section that ships with the free plugin:
/*
@section
{
"name": "FAQ",
"category": "content",
"heading_level": "h2",
"settings": [
{ "id": "eyebrow", "type": "text", "label": "Eyebrow", "default": "" },
{ "id": "headline", "type": "text", "label": "Headline", "default": "Frequently Asked Questions" },
{ "id": "subtext", "type": "textarea", "label": "Sub Text", "default": "" }
],
"blocks": [
{
"type": "faq",
"name": "Question",
"limit": 20,
"settings": [
{ "id": "question", "type": "text", "label": "Question", "default": "What is your return policy?", "required": true },
{ "id": "answer", "type": "richtext", "label": "Answer", "default": "We offer a 30-day hassle-free return on all orders." }
]
}
],
"max_blocks": 20
}
*/
The template then reads each value with the helper functions. In the free edition:
$blocks = slbuild_get_blocks();
$eyebrow = slbuild_get_field( 'eyebrow' );
$headline = slbuild_get_field( 'headline' );
$subtext = slbuild_get_field( 'subtext' );
Values are stored raw and must be escaped when you print them.
Tailwind classes in your own sections
The bundled stylesheet covers only the starter sections. Sections you write can use any class your theme’s own Tailwind build contains. See theme integration.
Related: SLB documentation · Getting started · Free vs paid
Last updated
