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

pdoField

This snippet has the functionality of both getResourceField and UltimateParent, that is, it displays any field from the specified resource or of its parent, including TV values.

Unlike its analogue it works with documents in any context and has the ability to specify additional parameters in the snippet call, allowing output of resources normally not displayed, for example, hidden resources. By specifying the parameter &class it can get the field of any MODX object. It may be called as an [Output Modifier] 3.

Properties

It takes [the general properties and sampling results] 4 of pdoTools and some of its own:

PropertyDefaultDescription
&idCurrent resourceResource ID.
&fieldpagetitleResource field.
&topSelects the root-level parent of the specified resource.
&topLevelSelects the resource's parent at this level from the root level.
&defaultSpecifies the resource field to return if &field is empty. Faster than the Output Modifier filter :default =
&outputIt specifies the string that is returned if &default and &field are all empty .
&toPlaceholderIf not empty, the snippet will save the field value to a placeholder with the same name, instead of displaying it to the screen.

If you specify &top or &topLevel, but not a &context, an additional request to the database will be made to determine the context.

Does not support working with chunk or snippet objects, as it returns only one field.

Examples

The snippet can be used as an Output Modifier:

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

You can specify properties in a JSON array. For example, selecting the second parent of the resource and returning its «longtitle»:

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

But it is better to use a normal snippet call - it is faster and more convenient:

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