Skip to content

pbResources

A snippet for fetching and displaying MODX resources.

Parameters

ParameterDefaultDescription
includeBlocks0Attach PageBlocks to each resource. Adds a blocks field to the result.
blockNameComma-separated list of block names. If not specified, all blocks will be included.
includeTables0Attach data tables to each resource. Each table is added to the result as a separate field, using the table field name.
tableNameComma-separated list of table names. If not specified, all tables will be included.
includeFiles0Attach file galleries to each resource. Each gallery is added as a separate field, using the field name of the gallery-type block.
fileNameComma-separated list of gallery names. If not specified, all galleries will be included.

Examples

Display child resources

php
{'!pbResources'|snippet: [
    'tpl' => 'tplResource', 
]}

Display child resources from specific parents, excluding resources with IDs 9 and 11

php
{'!pbResources'|snippet: [
    'parent' => '6,7',
    'resources' => '-9,-11',
    'tpl' => 'tplResource', 
]}

Attach blocks, tables, and galleries to each resource

php
{'!pbResources'|snippet: [
    'tpl' => 'tplResource',
    'includeBlocks' => 1,
    'blockName' => 'Hero,About', // Attach only specific blocks
    'includeTables' => 1,
    'tableName' => 'sizes,seo_list as list', // Rename `seo_list` to `list` in result
    'includeFiles' => 1,
    'fileName' => 'gallery'
]}

seo_list is the name of the table, but you can rename it in the result using as, e.g. seo_list as list will return it under the list key.

Add pagination

html
<div id="pb-items">
  {'!pbResources'|snippet: [
      'tpl' => 'tplResource',
      'limit' => 12,
      'showPagination' => 1,
  ]}
</div>
<div id="pb-loadmore" class="d-flex js-center">
  {'pls.loadmore'|placeholder}
</div>
<hr>
<nav id="pb-pagination" aria-label="Page navigation">
  {'pls.pagination'|placeholder}
</nav>

© PageBlocks 2019-present