Building blocks
Lists, InnerBlocks and the Repeater
Lists: four ways, and which to choose
Not everything that appears more than once is a list a person adds to. Choose by what the content is:
- Separate fields — a few things that are not the same kind (a heading and one button; two services drawn
differently). One field each. Example:
examples/blocks/demo-hero. - A repeater field — like items with a few simple values each (stats: a figure and a caption; logos; a row of
links).
type: "repeater"withfieldsfor one row: the sidebar shows the rows, with Add, remove and drag to reorder. Stored as an array of rows, each{ _id, …sub-fields }. Inrender.phploop the rows ((array) $attributes['stats'], each row(array) $row); a text sub-field can be typed on the canvas (data-gcb-row/data-gcb-subfield, below). Example:examples/blocks/lists-stats. - Child blocks — like items rich enough to be blocks of their own (cards with a picture, an icon, words and a button;
accordion items). The parent's
render.phpprints a<repeater allowedblocks='["gcb/card"]' addbuttonlabel="Add card" />marker; the editor turns it into an Add / reorder area on the canvas and the page renders the children there. Each child is its own block folder with its ownblock.fields.json. Notype: "repeater"field is needed for this — the children are the data. Example:examples/blocks/demo-feature-triowithdemo-feature-item. - Content that lives somewhere else — a site's menu (WordPress's Navigation, edited in Appearance → Editor), its logo
and name (Settings), its posts (a
query-loopfield). Read it; don't copy it into fields. Example:examples/blocks/lists-header.
A repeater field and child blocks are two different things that share the word "repeater": the field is rows in the sidebar; the marker is blocks on the canvas.
How the editor shows the children: editLayout (always set it)
The <Repeater> marker says how its children are laid out while they are edited (the page is not affected — it
renders the children where the marker is). Left out, the editor shows them as a carousel, one card at a time with
arrows and dots, whatever the block draws — so a grid of cards, an FAQ or a list of services looks broken to the person
editing it. Set it on every marker:
<Repeater allowedBlocks='["gcb/card"]' addButtonLabel="Add card" min="1" editLayout="grid" />editLayout | The editor shows | Use for |
|---|---|---|
grid | the children where the block's own markup and CSS put them (WYSIWYG) | almost everything: cards in a grid, a row of stats, services, logos — the usual choice |
stacked | every child as a numbered card, top to bottom | long lists whose page layout is hard to edit in (a timeline, a vacancy list) |
accordion | every child as a collapsible row, one open | many long items: FAQs where each answer is long |
tabs | one child at a time, with a tab strip | items the page shows as tabs |
filmstrip | one big child with thumbnails beneath | slides that are mostly a picture |
overflow | a strip of cards scrolled sideways | wide items in a row |
carousel | one at a time with arrows (the default) | only a block that IS a one-slide-at-a-time carousel on the page |
(Any value not in the list behaves as grid.)
A part that styles its items as its direct children needs the storyboard in the editor. The editor wraps every
child block in elements of its own, so CSS like .track > * or .accordion > .item no longer reaches the children on
the canvas: a carousel's slides collapse into thin columns, an accordion's buttons lose their look. Use editLayout="grid"
and give the theme a small editor-only stylesheet (.editor-styles-wrapper …, loaded on enqueue_block_assets in the
admin) that shows the items the storyboard way — every slide at once (a grid of them), every answer open — looking as they
do on the page. See "Theme blocks: the is-live convention" below.
A child's outer element gets the block's class (get_block_wrapper_attributes()). If that element is also a kit part
(data-gcb-kit="…"), the class marks it as the design's own and the part's look stands aside (data-gcb-own). Make the
child's outer element a plain wrapper and put the part inside it — or let the outer element be an item the part looks
for by attribute (an accordion's data-gcb-kit-item), not the part itself.
A child's number, and its parent's settings (block context)
A repeater's child is rendered on its own in the editor, so it can't count
its siblings in markup — and a CSS counter numbers the page, not the canvas.
Ask for context instead, the WordPress way, in the child's block.json:
"usesContext": ["gcb/index", "gcb/count"]and read it in render.php:
$n = (int) ($block->context['gcb/index'] ?? 0) + 1; // 0-based → 1, 2, 3 …
$of = (int) ($block->context['gcb/count'] ?? 0); // the parent's childrenThe page fills them as WordPress renders the children; the editor sends them
with each preview, and re-renders a child when it moves. A parent's own
settings reach a child the same way through core's providesContext on the
parent ("providesContext": { "my-kit/tint": "tint" }) and usesContext on
the child. Only blocks that ask get context — the rest aren't re-rendered
when their siblings move.
The markers in the code
Reference, generated from the plugin source
<Repeater> reads these attributes (in src/utils/parse-preview.js): allowedBlocks, addButtonLabel, addButton, editLayout, min, max, defaultChildren, template.
<InnerBlocks> reads: data-gcb-slot, allowedBlocks, template, templateLock.
HTML attribute names are not case-sensitive, so allowedBlocks and allowedblocks are the same attribute. List-valued attributes (allowedBlocks, template) take JSON in single quotes.
editLayout values the editor knows (REPEATER_LAYOUTS in src/repeater-layouts.jsx): carousel (Carousel), stacked (Stacked), tabs (Tabs), accordion (Accordion), filmstrip (Filmstrip), overflow (Overflow). Any other value — grid included — takes the default branch and the children render where the block's own markup puts them. When a marker sets no editLayout, the editor uses carousel. When a pin-map field places the children, the layout is placed whatever the marker says.
Several areas in one block
Reference, generated from the plugin source
A block can hold more than one InnerBlocks area: give each <InnerBlocks> marker a number, data-gcb-slot="0", data-gcb-slot="1" and so on.
each data-gcb-slot="N" marker takes the Nth inner block, where the design put it. When the markers and the inner blocks do not pair one to one (a person added or removed one), every inner block goes in the first marker, as before, and the others take nothing — never a region twice. Without numbered markers, every marker takes them all (replace).
In the editor, the editor gives a block one inner-blocks store, so every region is edited in the first slot; the front end puts each in its own (InnerBlocksReplacer)
See also The InnerBlocks repeater and the repeater field.