Often when developing sites, you need to get the necessary fields of some resources, for example, display a phone in the header of the site, which the manager could change in the "Contacts" resource. So, let's look at how to do this with snippets.
fastfield
This snippet has more features than getResourceField, and it has convenient syntax.
You can download fastField from the official repository - https://modx.com/extras/package/fastfield
The syntax of the call looks like this:
[[# resourceID.field]]
Where resourceID - ID of the desired resource, field - field name.
Examples of using the fastField plugin:
[[# 1.pagetitle]] - Output of the pagetitle resource with ID = 1;
[[# 1.tv.myTV]] - TV output with the name myTV for the resource with ID = 1;
[[# 1.properties.articles.articlesPerPage]] - Output of resource parameters with ID = 1;
[[# [[* * parent]]. introtext: default = `[[# [[* * parent]]. description]]`]] - Displays the annotation of the resource’s parent and if it is empty, it displays a description (fastField supports input filters - output);
[[# POST.name]] - the value of $ _POST ['name'] (and other global resources, similar to the getReqParam snippet)
Global arrays are supported: $ _GET, $ _POST, $ _REQUEST, $ _SERVER, $ _FILES, $ _COOKIE, $ _SESSION. The array type after sharp (#) is case sensitive. The element name of the array is also case sensitive. You can use the non-cacheable tag [[! # Get.name]] for cached resources.
Attention! Use the I / O filter: notags to prevent XSS attacks (for example: [[! # Get.name: notags]])
pdoField
The snippet is included in the pdoTools package, you can download it here - https://modstore.pro/packages/utilities/pdotools or in the official repository - https://modx.com/extras/package/pdotools
This snippet simultaneously has the capabilities of getResourceField and UltimateParent, that is, it displays any field of the specified resource or its parent, including TV parameters.
The difference from analogues is the work with documents of any contexts and the ability to specify additional parameters when fetching, which eliminates the need to display fields, for example, hidden resources. Also, by specifying the & class parameter, you can get the field of any MODX object. It can be called as an output filter.
A snippet can be called as an output filter:
[[* id: pdofield = `longtitle`]]
Or
[[pdoField?
& id = `[[* id]]`
& field = `longtitle`
& top = `2`
]]
PdoField also includes the fastField syntax:
[[# resourceID.field]]
See all the snippet parameters in the documentation here - https://docs.modx.pro/components/pdotools/snippets/pdofield
fastfield
This snippet has more features than getResourceField, and it has convenient syntax.
You can download fastField from the official repository - https://modx.com/extras/package/fastfield
The syntax of the call looks like this:
[[# resourceID.field]]
Where resourceID - ID of the desired resource, field - field name.
Examples of using the fastField plugin:
[[# 1.pagetitle]] - Output of the pagetitle resource with ID = 1;
[[# 1.tv.myTV]] - TV output with the name myTV for the resource with ID = 1;
[[# 1.properties.articles.articlesPerPage]] - Output of resource parameters with ID = 1;
[[# [[* * parent]]. introtext: default = `[[# [[* * parent]]. description]]`]] - Displays the annotation of the resource’s parent and if it is empty, it displays a description (fastField supports input filters - output);
[[# POST.name]] - the value of $ _POST ['name'] (and other global resources, similar to the getReqParam snippet)
Global arrays are supported: $ _GET, $ _POST, $ _REQUEST, $ _SERVER, $ _FILES, $ _COOKIE, $ _SESSION. The array type after sharp (#) is case sensitive. The element name of the array is also case sensitive. You can use the non-cacheable tag [[! # Get.name]] for cached resources.
Attention! Use the I / O filter: notags to prevent XSS attacks (for example: [[! # Get.name: notags]])
pdoField
The snippet is included in the pdoTools package, you can download it here - https://modstore.pro/packages/utilities/pdotools or in the official repository - https://modx.com/extras/package/pdotools
This snippet simultaneously has the capabilities of getResourceField and UltimateParent, that is, it displays any field of the specified resource or its parent, including TV parameters.
The difference from analogues is the work with documents of any contexts and the ability to specify additional parameters when fetching, which eliminates the need to display fields, for example, hidden resources. Also, by specifying the & class parameter, you can get the field of any MODX object. It can be called as an output filter.
A snippet can be called as an output filter:
[[* id: pdofield = `longtitle`]]
Or
[[pdoField?
& id = `[[* id]]`
& field = `longtitle`
& top = `2`
]]
PdoField also includes the fastField syntax:
[[# resourceID.field]]
See all the snippet parameters in the documentation here - https://docs.modx.pro/components/pdotools/snippets/pdofield
No comments: