Skip to content

Authoring Block Blueprints, Tokens & Packs

Every YAML file in ./site/blocks/*.yaml (and in registered module packs) compiles via BlockBlueprintCompiler into a canonical 3+ tab anatomy: Content (_blocks_tab_content) -> optional custom tabs -> Settings (_blocks_tab_settings) -> Advanced (_blocks_tab_advanced).

Declarative Block Ontology (BlockOntology)

Section titled “Declarative Block Ontology (BlockOntology)”

Declare placement and structural behavior directly in YAML instead of writing custom PHP/TS checks:

Key Allowed Values / Format Purpose
role element, container, item, opener, slot, reference Declares the block’s structural role (element standalone, container nested type: blocks, item compact child, opener flat-stream divider, slot Page Slot, reference Reusable pointer).
root bool Allows placement directly at the root of a block stream.
allowedParents ['@root'], ['@container'], ['row'], ['grid.items'] Restricts which parents or named child slots ({parent}.{slot}) may hold this block.
allowedChildren ['@element', '@slot', '@reference'] or block handles Restricts child blocks inside a container using explicit names or @role wildcards.
allowedContexts / disallowContexts page, template_layout, global_layout, panel_layout, reusable Restricts where the block may appear (for example disallowContexts: ['panel_layout']).
opener { wrapsInto, childField, collapseEmpty, autoWrap, widthField, tabletWidthField, ... } Folds flat-stream dividers (such as section_break or column_break) deterministically via StreamFolder.
grid { columns, childOpener, sourceField, childrenKey, widthField, tabletWidthField, presets } Computes CSS-agnostic meta.grid = { columns, span, spanTablet, ratio, index, count } via GridSpanCalculator and unlocks the Studio Grid Presets bar.
transforms Map of target block handles and field mappings Enables lossless in-place cross-block conversion (composeHtml, extractHtml, stripHtmlFallback, urlToLinkMedia, child slots) in the editor menu.
previewImage / previewImageDark URL strings Custom Light and Dark picker thumbnails. When omitted, WireframePreviewGenerator renders theme-reactive SVG wireframes automatically (extensible via WireframePreviewGenerator::registerGenerator()).

Shared Design Tokens (site/blocks/_tokens.yaml)

Section titled “Shared Design Tokens (site/blocks/_tokens.yaml)”

Define reusable token families once in ./site/blocks/_tokens.yaml (TokenGroupRegistry):

  • Standard token groups: surface, column_surface, text_color, text_size, card_variant, button_variant, badge_variant, alert_tone, plus panel_surface.
  • Each token entry defines { label, class, iconClass }, keeping YAML blueprints CSS-framework-agnostic while letting your frontend or block pack map token keys to utility classes.

Conditional Expressions & Selective @fieldset: Imports

Section titled “Conditional Expressions & Selective @fieldset: Imports”
  • Declarative expressions: Control field state dynamically in the editor using show, hide, enable, disable, and require expressions.
  • Selective @fieldset: imports: Reuse shared fieldsets from ./site/blocks/fieldsets/*.yaml with only, except, and overrides (pass ~ or false inside overrides to clear an inherited conditional or default key):
tabs:
content:
fields:
'@fieldset:content_heading':
overrides:
title:
required: true
'@fieldset:content_body': ~
'@fieldset:content_link': ~

Module Block Packs & extend: true Inheritance

Section titled “Module Block Packs & extend: true Inheritance”

Modules can ship reusable block libraries with zero cold-boot cost by declaring 'blocksPack' => true in getModuleInfo() and hooking Blocks::registerBlockPacks:

<?php
declare(strict_types=1);
namespace ProcessWire;
$this->wire()->addHookAfter('Blocks::registerBlockPacks', static function (HookEvent $event): void {
/** @var Blocks $blocks */
$blocks = $event->arguments(0);
$blocks->registerBlockPack(
'my_pack',
__DIR__ . '/blocks',
__DIR__ . '/views',
$blocks->wire()->config->urls->siteModules . 'MyPack/dist/pack.css',
);
});

Projects override or extend any pack block cleanly without copying the entire file by creating ./site/blocks/{block}.yaml with extend: true (or scaffolding it via php vendor/bin/wire make:block card --extend).

Next steps