Skip to content

pbList

Universal lister with built-in pagination. Point it at a model, give it a chunk, get a paginated list — without writing a controller for it.

[[!pbList? &model=`PbResource` &parent=`[[*id]]` &tpl=`chunk:myItem` &limit=`10`]]

Parameters

ParameterDefaultDescription
modelPbResourceModel short name, resolved under PageBlocks\App\Models\. An unknown name is logged and renders nothing.
tplRequired. Chunk for one row, receives item. Prefix with chunk: for a MODX chunk.
parentShorthand for "owned by resource N" (model_id = N).
parent_typemodDocumentMorph class of the owner, when it is not a resource.
whereConditions as JSON: {"template":4} or [["price",">=","100"]].
scopespublishedEloquent scopes, comma-separated. Pass an empty value to disable.
orderBy / sortbymenuindex"menuindex", "menuindex desc" or JSON {"price":"desc"}.
limit10Rows per page.
classd-flex flex-column gap-3CSS classes of the wrapper.
loadmoreRender a "load more" button instead of relying on page links.
loadmoreLabelПоказать ещёButton caption.

What it renders

html
<div class="d-flex flex-column gap-3" id="pb-items"
     data-pb-key="pblist_a1b2…" data-pb-total="137" data-pb-last-page="14">
  <!-- rows rendered through tpl -->
</div>
<div class="pb-pagination mt-4" pb-pagination>
  <!-- numbered links -->
</div>

data-pb-key is a hash of the resolved query, cached server-side. Pagination sends that one key back over AJAX, so the browser never sees — and cannot tamper with — the conditions. Without JavaScript the numbered links still work: they carry ?page=N and re-run the snippet server-side.

Examples

Children of the current resource

[[!pbList? &parent=`[[*id]]` &tpl=`chunk:childItem` &limit=`20`]]

Another model, filtered and sorted

[[!pbList?
    &model=`PbVacancy`
    &tpl=`chunk:vacancyCard`
    &where=`{"city_id":7}`
    &orderBy=`{"published_at":"desc"}`
    &limit=`12`
]]

"Load more" instead of page numbers

[[!pbList? &parent=`[[*id]]` &tpl=`chunk:childItem` &loadmore=`1` &limit=`9`]]

From a Fenom template

Named parameters, Smarty style — space separated, no parentheses and no commas:

php
{pbList model='PbResource' parent=$modx->resource->id tpl='childItem' limit=10}

Here a bare tpl means the file chunk core/App/elements/chunks/childItem.tpl.

A chunk that does not exist renders as nothing

Missing templates are not an error — they produce an empty string and a DEBUG line in the MODX log. An empty list with a non-zero data-pb-total usually means a typo in tpl.

© PageBlocks 2019-present