Dynamic, Smart Content & Dependencies
Blocks turns static design blocks into live data-driven components without requiring custom PHP queries in every template.
Type-Safe Field Mapping (FieldMappingCatalog & FieldMappingEvaluator)
Section titled “Type-Safe Field Mapping (FieldMappingCatalog & FieldMappingEvaluator)”When a block blueprint declares dynamic: true, editors can bind its fields directly to ProcessWire Pages or Entries records:
blockMode: single: Binds a single block to the current page, a selected page, or an Entry record using type-compatible field mapping (text -> text,media -> image,link -> url, etc.).blockMode: multiple(Smart Content): Queries a collection of Pages or Entries (SmartContentResolver, guarded byDynamicSelectorGuard), maps each item’s fields automatically, deduplicates cross-block items viaReferenceStore, and emits an HMAC-signedSignedSmartQueryCodectoken for interactive/_blocks/smartpagination, sorting, and filtering (with progressive?blocks[{id}][...]URL fallback in native PHP).
Dynamic Item Templates (role: item + dynamic: true)
Section titled “Dynamic Item Templates (role: item + dynamic: true)”Declare dynamic: true on any role: item child blueprint (such as card, gallery_item, or list_item). Inside any blockMode: multiple container whose own Smart Content is turned off, editors can switch an individual child item between:
Single: Bind one static item slot to a specific Page or Entry.Multiple (Repeat This Template): Expand matching Pages or Entries in place right between surrounding static sibling items, optionally emittingmeta.dynamicGroupssigned/_blocks/smartslices for live pagination.
Custom Page Class Overrides (Page::getBlockParams())
Section titled “Custom Page Class Overrides (Page::getBlockParams())”For computed values that cannot be mapped directly from a single field, define getBlockParams() on any ProcessWire Custom Page Class (or hook Blocks::resolveBlockParams for Page and EntryItem sources):
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Blocks\Cache\DependencyCollector;
class RoutePage extends DefaultPage{ /** * @param array<string, mixed> $block * @return array<string, mixed> */ public function getBlockParams(array $block, DependencyCollector $deps): array { $deps->addTag('page:' . $this->id);
return [ 'badge' => (int) $this->get('duration_days') . ' Days', 'subtitle' => 'From EUR ' . number_format((float) $this->get('weekly_rate'), 0), ]; }}For collection items, getBlockParams() can return ['item' => [...], 'parent' => [...]] (parent overrides apply only when all resolved items share the same template or entry type).
Output-Based Block Dependencies (_blocks_key & _blocks_depends_on)
Section titled “Output-Based Block Dependencies (_blocks_key & _blocks_depends_on)”Hide enclosing headings, wrapper rows, “View All” buttons, or empty-state notices automatically based on whether another block produced output:
- Assign an internal
_blocks_keyidentifier (^[a-zA-Z][a-zA-Z0-9_-]*$, never rendered as an HTMLid) on any non-slot block in its Advanced tab (for examplerelated_routes). - On a sibling, wrapper, or forward block, configure
_blocks_depends_on:targets: One or more_blocks_keyidentifiers.condition:has_output,is_empty,has_more, ormin_count(withminCount).match:allorany.
- Two-Phase Resolution:
BlockTreeResolverresolves Layout Body + Page Slot streams in Phase 1 intoBlockOutputRegistry, then runsBlockDependencyPrunerin Phase 2 to prune failing blocks monotonically and collapse emptied containers cleanly (Global Header, Footer, and Panel scopes stay isolated).