Rendering: React/Inertia, PHP & Caching
Blocks resolves every page through BlockTreeResolver once and delivers the same normalized tree across React 19 / Inertia v3, native PHP templates, and Headless JSON, backed by BlockCacheManager.
React 19 / Inertia v3 + Shared OnceProp Layout Regions
Section titled “React 19 / Inertia v3 + Shared OnceProp Layout Regions”Split page-independent Global Header and Footer regions into content-hashed Inertia v3 OnceProp payloads via $blocks->layoutRegions($page) so browsers never re-download header/footer JSON during SPA navigation:
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Inertia\InteractWithInertia;
class DefaultPage extends Page{ use InteractWithInertia;
/** * @return array<string, mixed> */ public function inertiaWithData(): array { $blocks = Blocks::instance($this); if (!$blocks instanceof Blocks) { return ['blocks' => null]; }
$props = [ 'blocks' => $blocks->forPage($this, ['excludeSharedRegions' => true]), ]; $regions = $blocks->layoutRegions($this); $inertia = $this->inertia();
foreach (['header' => 'blocksHeader', 'footer' => 'blocksFooter'] as $slot => $propName) { $meta = $regions[$slot] ?? null; if ($meta !== null && $meta['shared']) { $props[$propName] = $inertia->once(static fn(): array => [ 'key' => $meta['key'], 'nodes' => $meta['nodes'], 'smartEndpoint' => $blocks->smartEndpointUrl(), ])->as($meta['key']); } }
return $props; }}Native PHP Views (PhpBlockRenderer & BlockScope)
Section titled “Native PHP Views (PhpBlockRenderer & BlockScope)”Place PHP block templates in ./site/templates/blocks/{type}.php. Inside each view, $renderer (PhpBlockRenderer / re-entrant BlockScope) exposes safe helpers (has, hasAny, texts, esc, escText, bool, int, match, cx, blockAttrs, gridMeta, hideOn, renderChildren, media, link, smartLink, wrapLink, renderImage, renderProse, items, onceScript):
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Blocks\Renderer\PhpBlockRenderer;
/** @var PhpBlockRenderer $renderer */if (!$renderer->hasAny('title', 'content')) { return;}
[$title, $content] = $renderer->texts('title', 'content');$link = $renderer->link('link');$attrs = $renderer->blockAttrs($renderer->cx( 'rounded-2xl border p-6', $renderer->commonClasses(),));?><div<?= $attrs ?>> <?php if ($title !== '') { ?> <h3><?= $renderer->esc($title) ?></h3> <?php } ?> <?php if ($content !== '') { ?> <?= $renderer->renderProse($content) ?> <?php } ?> <?php if ($link['isUsable']) { ?> <?= $renderer->wrapLink($link, $renderer->esc($link['label'] !== '' ? $link['label'] : $title)) ?> <?php } ?></div>Render full pages, Global Layouts, or Panel Layouts from your template controller:
<?php
declare(strict_types=1);
namespace ProcessWire;
$blocks = Blocks::requireInstance($page);$headerHtml = $blocks->renderLayout('aegean_header');$bodyHtml = $blocks->renderPage($page);$panelHtml = $blocks->renderPanel('aegean_fleet_menu');Keyed Per-Block Assets (BlockAssetRegistry)
Section titled “Keyed Per-Block Assets (BlockAssetRegistry)”Register conditional CSS, JS, <link>, or batched Vite entries inside a PHP block view via $renderer->useStyle(), useInlineStyle(), useScript(), useInlineScript(), useLink(), and useVite().
- Assets are deduplicated by key, rolled back transactionally if a block returns empty output, and replayed automatically on
Blocks.Htmlcache hits. - Output collected assets in your page shell with
$blocks->assets()->renderHead()and$blocks->assets()->renderFooter().
Semantic Plain HTML & Text Extraction (PlainHtmlExtractor)
Section titled “Semantic Plain HTML & Text Extraction (PlainHtmlExtractor)”Extract layout-free semantic HTML or word-boundary plain text for search indexing, RSS feeds, or SEO meta descriptions:
<?php
declare(strict_types=1);
namespace ProcessWire;
$blocks = Blocks::requireInstance($page);$plainHtml = $blocks->toPlainHtml($page);$excerpt = $blocks->toPlainText($page, 160);Customize extraction per block type via $blocks->registerPlainBlockExtractor() and $blocks->registerJsonNodeNormalizer().
Tag-Indexed Caching (BlockCacheManager)
Section titled “Tag-Indexed Caching (BlockCacheManager)”BlockCacheManager caches resolved trees (Blocks.Tree) and rendered HTML (Blocks.Html) under Blocks.TagIndex, automatically partitioned by language, role tier (guest, su, or sorted role IDs), field, and entry context. Saving a page, Entry, Layout, Reusable, Preset, or Default invalidates only affected tags surgically (or call $blocks->invalidateTags(['pricing:plans']) directly).