Skip to content

PageBlocks

Snippet for displaying blocks or tables.

Parameters

ParameterDefaultDescription
ModelTypeDocumentDocument model
classKeypbBlockValueTable class. Possible values: pbBlockValue, pbTableValue
tplChunk for blocks. By default, it is used from the block itself.
sortbymenuindexSort field
sortdirascSort order
limit0Number of records displayed. 0 - means without limits.
offset0Skipping values from the start
returndataOutput format of values. Possible values: data, json
fileElements0Use file chunks
idID of blocks or table. If specified, the where parameter is ignored.
context_keycurrent resourceBy default, the current resource context is used.
resource_idcurrent resourceBy default, the ID of the current resource is used.
collection_id0ID of the collection. Used for tables.
where[]Array of additional parameters for filtering results.

Examples

For blocks, it's sufficient to call as follows:

php
{'!PageBlocks'|snippet}

If file chunks are used:

php
{'!PageBlocks'|snippet: [
    'fileElements' => 1
]}

Display a single block with id = 1:

php
{'!PageBlocks'|snippet: [
    'id' => 1
]}

Use conditions for displaying blocks:

php
{'!PageBlocks'|snippet: [
    'where' => [
        'model_type' => 'Document', // MODX\Revolution\modDocument
        'model_id' => $_modx->resource->id,
        'context_key' => $_modx->resource->context_key,
        'published' => 1,
        'deleted' => 0,
    ]
]}

Retrieve tables

php
{'!PageBlocks'|snippet: [
    'classKey' => 'pbTableValue',
    'collection_id' => 1,
    'tpl' => 'name_chunk'
]}

© PageBlocks 2019-present