Docs / Inlay / Sections

Sections

A page is a list of sections - full-width bands such as a hero or a pricing table. A section can be written two ways, and nothing downstream (the picker, the inspector, rendering, publishing, revisions) treats them differently:

  • a single-file section: one Blade file that declares its settings at the top
  • a class-based section: a Blade class component implementing InlaySection

Single-file sections

{{-- resources/views/inlay/sections/hero.blade.php --}}
<?php

use App\Enums\ImageSize;
use WeArePixel\Inlay\Schema\Settings;
use WeArePixel\Inlay\SingleFile\Section;

section(
    Section::make('hero')
        ->name('Hero')
        ->category('Headers')
        ->description('A large banner with a heading and image.')
        ->icon('layout-header')
        ->keywords(['banner', 'header'])
        ->settings(
            Settings::make()
                ->text('heading')->label('Heading')->default('Welcome')
                ->select('imageSize')->label('Image size')->options(ImageSize::class)->default(ImageSize::Large)
        )
);
?>
<section>
    <h1>{{ $heading }}</h1>
    <img class="{{ $imageSize === ImageSize::Small ? 'max-w-md' : 'w-full' }}" src="...">
</section>

Everything after ?> is ordinary Blade, with every setting available as a variable. It isn't a Livewire component, but it can contain <livewire:...> tags like any view.

Every top-level setting needs a default

A single-file section has no constructor to infer defaults from, so ->default(...) is required on every top-level setting. Omitting one fails registration:

Single-file section [hero] setting [heading] has no default(). A single-file section has no constructor to infer one from - every top-level setting must declare its own default via ->default(...).

Registering

use WeArePixel\Inlay\Facades\Inlay;

Inlay::singleFileSections(resource_path('views/inlay/sections')); // every *.blade.php directly inside
Inlay::singleFileSection(resource_path('views/inlay/sections/hero.blade.php')); // one file

inlay:install puts the directory call in app/Providers/InlayServiceProvider.php. The handle comes from Section::make('hero'), not the filename. A handle already claimed by another section fails registration rather than silently overriding it.

Class-based sections

A Blade class component that implements the WeArePixel\Inlay\Contracts\InlaySection marker interface:

namespace App\Inlay\Sections;

use Illuminate\View\Component;
use Illuminate\View\View;
use WeArePixel\Inlay\Attributes\SectionMeta;
use WeArePixel\Inlay\Attributes\Text;
use WeArePixel\Inlay\Contracts\InlaySection;

#[SectionMeta(label: 'Hero', category: 'Headers', description: 'A large banner with a heading and image.', keywords: ['banner'])]
final class Hero extends Component implements InlaySection
{
    public function __construct(
        #[Text(label: 'Heading', maxLength: 80)]
        public string $heading = 'Welcome',
    ) {}

    public function render(): View
    {
        return view('sections.hero');
    }
}

Register it against a handle in config/inlay.php:

'sections' => [
    'hero' => \App\Inlay\Sections\Hero::class,
],

The handle is what's stored against a page, never the class name, so renaming or moving the class doesn't break existing pages.

A constructor parameter is only an editor setting when you declare it as one - with an attribute or in a static settings() method (see Settings). Other constructor dependencies are resolved by the container as usual.

For a class-based section, the constructor parameter's default and nullability are the source of truth for each top-level setting. A required, non-nullable parameter with no default fails registration.

Picker metadata

#[SectionMeta] (or the fluent name(), category(), description(), icon(), keywords(), thumbnail() on a single-file section) controls how the section appears in the section picker. Every field is optional. Without a label the picker uses the handle headlined; without a category it's grouped under "Uncategorised". keywords are searched alongside the label, description and category.

A thumbnail gives the section a picture in the picker, so editors choose by how it looks rather than by name. Pass a path relative to public/, or a full URL:

#[SectionMeta(label: 'Hero', category: 'Headers', thumbnail: '/images/inlay/hero.webp')]
section(
    Section::make('hero')->thumbnail('/images/inlay/hero.webp')
);

Category is presentational only. To restrict which sections a kind of page allows, use a Page Definition.

Presentation stays yours

Inlay never injects markup into a section's output. Settings decide which branch your view takes; there's no way for an editor to add classes or markup your view didn't provide for.

Registration errors

These are raised when the section is first resolved, not when an editor touches the field:

Situation Message
A setting has no matching constructor parameter Section [...] declares a setting [...] with no matching constructor parameter.
A non-nullable constructor parameter has no default Section [...] setting [...] has no constructor default and is not nullable. ...
->options(Enum::class) doesn't match the parameter's enum type Section [...] setting [...] declares options for [...], but the constructor expects [...].
The same setting is declared twice Duplicate setting [...] declared twice in the same settings definition.
A modifier is called before any field ...() must follow a field definition.
->options() is given a class that isn't an enum [...] passed to options() is not an enum.
A single-file section never calls section(...) [...] does not declare a single-file section - it must call section(Section::make(...)) in a PHP block at the top of the file.
No file at the given path No single-file section or block found at [...].
A single-file handle is already registered Cannot register single-file section [...] - a class-based section is already registered for that handle.
Discovery Call

One call.
We'll both know.

20 minutes to walk through your project, ask the hard questions, and work out honestly if we're the right team for it.

  • One call per day - it gets our full attention
  • Australia's only Laravel Premier Partner
  • Trusted by Chemist Warehouse, HelloFresh and Youfoodz
  • Senior engineers only - no juniors on your project
  • Brisbane-based, onshore team

Press Esc to close  ·  B to reopen