Skip to content

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.

SnippetWhat it does
pbListUniversal lister with built-in pagination over any model
pbBlocksRenders the constructor blocks of a resource
pbResourcesFlat list of MODX resources
pbUsersFlat list of users
pbMenuResource tree for navigation
pbFiltersReady-made filter form for a constructor table
pbJsonRenders 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:

php
{'!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:

ParameterDefaultDescription
tplChunk rendering a single row. Without it the snippet returns the raw collection, which is only useful from Fenom.
tplWrapperChunk wrapping the whole output. Receives output and total.
tplEmptyChunk rendered instead of the output when nothing was found.
outputSeparator\nGlue between rendered rows.

Inside tpl the row is available as item, and its 1-based position as idx:

php
<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 myItem

If you are calling the snippet from a MODX template, you almost certainly want chunk:.

© PageBlocks 2019-present