API / Minn\Theme / TemplatePatterns

TemplatePatterns final readonly class

Minn\Theme\TemplatePatterns · public/minn/src/Minn/Theme/TemplatePatterns.php · 88 lines

A template can name a pattern instead of carrying its blocks, and the reference hands the caller the blocks: every "wp:pattern" delimiter is replaced by the pattern's own markup before a template or part is served. A slug the theme does not know stays exactly as it is, which is what tells an editor the pattern went missing rather than the block.

Used by 1

Constants and properties

privateTAG = '<!-- wp:pattern'
privateDEPTH = 5

Public

staticexpand(string $markup, Minn\Theme\Theme $theme, int $depth = 0): string#

Markup with its pattern blocks replaced by the patterns' content.

Internals 4

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatecloserAt(string $markup, int $at): ?int#

The offset past a self-closing delimiter's "/-->", or null when it is not one.

privatepattern(string $attributes, Minn\Theme\Theme $theme): ?string#
privatestamped(string $markup, array $header): string#

The pattern's own name rides on the block it opens, so an editor can still see which pattern a stretch of blocks came from. Only a pattern that IS one block gets the stamp: several blocks have no single wrapper to carry the name, and the reference leaves those anonymous. The stamp goes on the pattern's raw markup, before any pattern nested inside it is spliced in, so when that one block is itself a pattern reference the stamp goes away with it.

$headerarray<string, mixed>
privateisOneBlock(string $markup): bool#