Fields
- Type
- Class
- Namespace
- craft\web\twig\variables
- Inherits
- craft\web\twig\variables\Fields
- Since
- 3.0.0
- Deprecated in
- in 3.0.0
Fields provides an API for accessing information about fields. It is accessible from templates via craft.fields
.
View source (opens new window)
# Public Methods
Method | Description |
---|---|
getAllFieldTypes() | Returns all available field type classes. |
getAllFields() | Returns all fields. |
getAllGroups() | Returns all field groups. |
getFieldByHandle() | Returns a field by its handle. |
getFieldById() | Returns a field by its ID. |
getFieldsByGroupId() | Returns all the fields in a given group. |
getGroupById() | Returns a field group by its ID. |
getLayoutById() | Returns a field layout by its ID. |
getLayoutByType() | Returns a field layout by its associated element type. |
# getAllFieldTypes()
Returns all available field type classes.
View source (opens new window)
Returns
string (opens new window)[] – The available field type classes
# getAllFields()
Returns all fields.
View source (opens new window)
Arguments
$indexBy
(string (opens new window), null (opens new window)) – The attribute to index the fields by
Returns
craft\base\FieldInterface[] – The fields
# getAllGroups()
Returns all field groups.
View source (opens new window)
Arguments
$indexBy
(string (opens new window), null (opens new window)) – The attribute to index the field groups by
Returns
craft\models\FieldGroup[] – The field groups
# getFieldByHandle()
Returns a field by its handle.
View source (opens new window)
Arguments
$handle
(string (opens new window)) – The field’s handle
Returns
craft\base\FieldInterface, null (opens new window) – The field, or null if it doesn’t exist
# getFieldById()
Returns a field by its ID.
View source (opens new window)
Arguments
$fieldId
(integer (opens new window)) – The field’s ID
Returns
craft\base\FieldInterface, null (opens new window) – The field, or null if it doesn’t exist
# getFieldsByGroupId()
Returns all the fields in a given group.
View source (opens new window)
Arguments
$groupId
(integer (opens new window)) – The field group’s ID$indexBy
(string (opens new window), null (opens new window)) – The attribute to index the fields by
Returns
craft\base\FieldInterface[] – The fields
# getGroupById()
Returns a field group by its ID.
View source (opens new window)
Arguments
$groupId
(integer (opens new window)) – The field group’s ID
Returns
craft\models\FieldGroup, null (opens new window) – The field group, or null if it doesn’t exist
# getLayoutById()
Returns a field layout by its ID.
View source (opens new window)
Arguments
$layoutId
(integer (opens new window)) – The field layout’s ID
Returns
craft\models\FieldLayout, null (opens new window) – The field layout, or null if it doesn’t exist
# getLayoutByType()
Returns a field layout by its associated element type.
View source (opens new window)
Arguments
$type
(string (opens new window)) – The associated element type
Returns
craft\models\FieldLayout – The field layout