Skip to content
  1. Extras
  2. pdoTools
  3. Snippets
  4. pdoField

pdoField

This snippet combines getResourceField and UltimateParent: it outputs any field of a specified resource or its parent, including TV parameters.

Unlike those, it works with documents in any context and allows extra select parameters (e.g. to exclude fields of hidden resources). With &class you can get a field of any MODX object. Can be used as output filter.

Parameters

Accepts general pdoTools select and output parameters plus:

ParameterDefaultDescription
&idCurrent documentResource ID.
&fieldpagetitleResource field.
&topSelects parent of &id at level &top.
&topLevelSelects parent of &id at &topLevel from context root.
&defaultResource field to return if &field is empty. Faster than :default= filter.
&outputString to return if both &default and &field are empty.
&toPlaceholderIf set, snippet stores data in placeholder instead of outputting.

If &top or &topLevel is used and &context is not set, an extra DB query will determine the context.

Snippet does not support chunks; it returns only one field value.

Examples

As output filter:

modx
[[*id:pdofield=`longtitle`]]

Parameters as JSON. Second parent and its longtitle:

modx
[[*id:pdofield=`{"top":2,"field":"longtitle"}`]]

Regular call is faster and clearer:

modx
[[pdoField?
  &id=`[[*id]]`
  &field=`longtitle`
  &top=`2`
]]