Intro
PageBlocks registers seven MODX snippets on install. They exist so the component is reachable from an ordinary MODX template: you paste a call, you get output. No controller, no route, no migration to our template engine.
| Snippet | What it does |
|---|---|
pbList | Universal lister with built-in pagination over any model |
pbBlocks | Renders the constructor blocks of a resource |
pbResources | Flat list of MODX resources |
pbUsers | Flat list of users |
pbMenu | Resource tree for navigation |
pbFilters | Ready-made filter form for a constructor table |
pbJson | Renders a JSON value through an inline template |
Calling them
Both spellings work. In a MODX template:
[[!pbList? &model=`PbResource` &parent=`[[*id]]` &tpl=`chunk:myItem` &limit=`10`]]In a Fenom template:
{'!pbList' | snippet: ['model' => 'PbResource', 'tpl' => 'chunk:myItem', 'limit' => 10]}Keep the ! — these snippets are meant to be uncached, otherwise MODX will freeze the first render into the page cache.
Array parameters are JSON
A MODX snippet receives every parameter as a string, so anything array-shaped is written as JSON and decoded by the snippet:
[[!pbList?
&model=`PbResource`
&tpl=`chunk:myItem`
&where=`{"template":4}`
&orderBy=`{"publishedon":"desc"}`
]]Invalid JSON is passed through untouched, so a plain 12,7,3 id list stays an id list.
Shared output parameters
pbResources, pbUsers, pbMenu and pbBlocks share one output contract — the same one pdoTools users already know:
| Parameter | Default | Description |
|---|---|---|
tpl | Chunk rendering a single row. Without it the snippet returns the raw collection, which is only useful from Fenom. | |
tplWrapper | Chunk wrapping the whole output. Receives output and total. | |
tplEmpty | Chunk rendered instead of the output when nothing was found. | |
outputSeparator | \n | Glue between rendered rows. |
Inside tpl the row is available as item, and its 1-based position as idx:
<div class="card">
<span class="num">{$idx}</span>
<a href="{$item->uri}">{$item->pagetitle}</a>
</div>Which chunk does tpl mean?
A bare name is a file chunk under core/App/elements/chunks/. Prefix it with chunk: to render an ordinary MODX chunk instead:
&tpl=`myItem` → core/App/elements/chunks/myItem.tpl
&tpl=`chunk:myItem` → MODX chunk named myItemIf you are calling the snippet from a MODX template, you almost certainly want chunk:.