What is getResourceField?
getResourceField is a simple snippet which can be used to display a single field, including template variables, of a different resource for MODx Revolution.
getResourceField was first released on September 16th, 2010 by paulmerchant, co-authored by Shaun McCormick.
The snippet can be retrieved through the Package Manager, or downloaded manually from the Repository.
The minimum tag is as follows:
This will output the pagetitle of the current resource.
||The resource ID to get the field from.
||The field or template variable name to return.
||When set to 1 or true, the field is considered to be a template variable.
||When set to 1 or true, the template variable will be processed according to its output settings.
||The value (string) to return if the field is not found or is empty.
Return the pagetitle from the resource with id 123:
Return the processed TV with name myTV of the parent resource, and if it is empty output 'Sorry, no data available':
[[getResourceField? &id=`[[*parent]]` &field=`myTV` &processTV=`1` &default=`Sorry, no data available`]]
Return the introtext field of the ultimate parent (note that this requires the UltimateParent snippet to be installed):
[[getResourceField? &id=`[[UltimateParent]]` &field=`introtext`]]
One error that this Snippet is prone to is deceptively subtle: you can end up with a redirect loop. Consider the example where you've defined a template variable on your homepage, e.g. [[*featured_article]], and you use this in your getResourceField Snippet call:
[[getResourceField? &id=`[[*featured_article]]` &field=`content`]]
If that TV is not set, the default behavior is to use the id of the current page. If your Snippet call is in the content of your page and you are requesting the content as your field, your Snippet can go down the rabbit hole and infinitely loop on itself, causing your page request to time out with too many redirects.
Bottom line: if the Snippet call is inside the same field that you are requesting (e.g. content), then make sure the id parameter never points to the current page.
Suggest an edit to this page.