Skip to content

pbBlocks

Renders the constructor blocks attached to a resource — the page body assembled in the builder.

[[!pbBlocks]]

Parameters

ParameterDefaultDescription
resourcecurrent resourceWhose blocks to render.
parentAlias of resource.
limitRender only the first N blocks.
offset0Skip the first N blocks.
tplChunk that receives each block as item. Without it every block renders through its own chunk, the one its constructor was configured with.

Plus tplWrapper, tplEmpty and outputSeparator — but only when tpl is given.

How output is chosen

Without tpl the snippet calls each block's own render(), which resolves the chunk from the block's chunk and chunk_path. That is the normal case: the builder already knows how each block looks.

With tpl you take that over — useful when the same blocks need different markup in a different place, or when you want to wrap each one.

Only published, only this language

The snippet uses the resource's blocks() relation, so it returns blocks that are published (published_at set and in the past), not soft-deleted, and belong to the current language. Unpublished blocks stay invisible on the front end without any extra condition on your side.

Examples

Body of the current page

[[!pbBlocks]]

Blocks of another page

[[!pbBlocks? &resource=`15`]]

First three blocks, then the rest

[[!pbBlocks? &limit=`3`]]
...
[[!pbBlocks? &offset=`3` &limit=`100`]]

From Fenom

php
{foreach $modx->resource->blocks()->get() as $block}
    {$block->render()}
{/foreach}

Nothing rendered?

Check published_at on the blocks before looking at routes or templates — an unpublished block is silently skipped.

© PageBlocks 2019-present