Skip to content

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 by DynamicSelectorGuard), maps each item’s fields automatically, deduplicates cross-block items via ReferenceStore, and emits an HMAC-signed SignedSmartQueryCodec token for interactive /_blocks/smart pagination, 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 emitting meta.dynamicGroups signed /_blocks/smart slices 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:

  1. Assign an internal _blocks_key identifier (^[a-zA-Z][a-zA-Z0-9_-]*$, never rendered as an HTML id) on any non-slot block in its Advanced tab (for example related_routes).
  2. On a sibling, wrapper, or forward block, configure _blocks_depends_on:
    • targets: One or more _blocks_key identifiers.
    • condition: has_output, is_empty, has_more, or min_count (with minCount).
    • match: all or any.
  3. Two-Phase Resolution: BlockTreeResolver resolves Layout Body + Page Slot streams in Phase 1 into BlockOutputRegistry, then runs BlockDependencyPruner in Phase 2 to prune failing blocks monotonically and collapse emptied containers cleanly (Global Header, Footer, and Panel scopes stay isolated).

Next steps