Skip to content

pbResources

Flat list of MODX resources. Use it when you need a simple list; for a paginated one use pbList.

[[!pbResources? &parent=`[[*id]]` &tpl=`chunk:resourceItem`]]

Parameters

ParameterDefaultDescription
idsComma-separated ids. Given ids, the output keeps the order you listed them in.
parentParent id, or several separated by commas.
templateTemplate id, or several separated by commas.
contextContext key, or several separated by commas.
visible0Only resources visible in menus.
published1Only published. Pass 0 to include unpublished.
whereExtra conditions as JSON: {"isfolder":1}.
sortbymenuindexField to sort by. Ignored when ids is given without it.
sortdirascasc or desc.
limitRows to return; empty means no limit.
offset0Rows to skip.

Plus the shared output parameters — tpl, tplWrapper, tplEmpty, outputSeparator — described in Intro.

Examples

Children of the current resource

[[!pbResources? &parent=`[[*id]]` &tpl=`chunk:resourceItem`]]

Specific resources, in the given order

[[!pbResources? &ids=`12,7,3` &tpl=`chunk:resourceItem`]]

Output order is 12, 7, 3 — not the order the database happens to return.

With a wrapper and an empty state

[[!pbResources?
    &parent=`5`
    &tpl=`chunk:resourceItem`
    &tplWrapper=`chunk:resourceList`
    &tplEmpty=`chunk:nothingFound`
    &limit=`10`
]]

tplWrapper receives the joined rows as output and their count as total:

php
<div class="list">
    <h2>Found: {$total}</h2>
    {$output}
</div>

From Fenom

The same data without the snippet layer:

php
{foreach resources(['parent' => 5, 'limit' => 10]) as $item}
    <a href="{$item->uri}">{$item->pagetitle}</a>
{/foreach}

© PageBlocks 2019-present