Craft 3 Class Reference

Class craft\web\twig\variables\Fields

Inheritance
craft\web\twig\variables\Fields
Available since version
3.0
Deprecated since version
in 3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/web/twig/variables/Fields.php

Fields provides an API for accessing information about fields. It is accessible from templates via craft.fields.

Public Methods
Method Description Defined By
getAllFieldTypes() Returns all available field type classes. craft\web\twig\variables\Fields
getAllFields() Returns all fields. craft\web\twig\variables\Fields
getAllGroups() Returns all field groups. craft\web\twig\variables\Fields
getFieldByHandle() Returns a field by its handle. craft\web\twig\variables\Fields
getFieldById() Returns a field by its ID. craft\web\twig\variables\Fields
getFieldsByGroupId() Returns all the fields in a given group. craft\web\twig\variables\Fields
getGroupById() Returns a field group by its ID. craft\web\twig\variables\Fields
getLayoutById() Returns a field layout by its ID. craft\web\twig\variables\Fields
getLayoutByType() Returns a field layout by its associated element type. craft\web\twig\variables\Fields

Method Details

getAllFieldTypes() public method #

Returns all available field type classes.

public string[] getAllFieldTypes ( )
return string[] The available field type classes

getAllFields() public method #

Returns all fields.

public craft\base\FieldInterface[] getAllFields ( \craft\web\twig\variables\string $indexBy null )
$indexBy string, null The attribute to index the fields by
return craft\base\FieldInterface[] The fields

getAllGroups() public method #

Returns all field groups.

public craft\models\FieldGroup[] getAllGroups ( \craft\web\twig\variables\string $indexBy null )
$indexBy string, null The attribute to index the field groups by
return craft\models\FieldGroup[] The field groups

getFieldByHandle() public method #

Returns a field by its handle.

public craft\base\FieldInterface, null getFieldByHandle ( \craft\web\twig\variables\string $handle )
$handle string The field’s handle
return craft\base\FieldInterface, null The field, or null if it doesn’t exist

getFieldById() public method #

Returns a field by its ID.

public craft\base\FieldInterface, null getFieldById ( \craft\web\twig\variables\int $fieldId )
$fieldId integer The field’s ID
return craft\base\FieldInterface, null The field, or null if it doesn’t exist

getFieldsByGroupId() public method #

Returns all the fields in a given group.

public craft\base\FieldInterface[] getFieldsByGroupId ( \craft\web\twig\variables\int $groupId, \craft\web\twig\variables\string $indexBy null )
$groupId integer The field group’s ID
$indexBy string, null The attribute to index the fields by
return craft\base\FieldInterface[] The fields

getGroupById() public method #

Returns a field group by its ID.

public craft\models\FieldGroup, null getGroupById ( \craft\web\twig\variables\int $groupId )
$groupId integer The field group’s ID
return craft\models\FieldGroup, null The field group, or null if it doesn’t exist

getLayoutById() public method #

Returns a field layout by its ID.

public craft\models\FieldLayout, null getLayoutById ( \craft\web\twig\variables\int $layoutId )
$layoutId integer The field layout’s ID
return craft\models\FieldLayout, null The field layout, or null if it doesn’t exist

getLayoutByType() public method #

Returns a field layout by its associated element type.

public craft\models\FieldLayout getLayoutByType ( \craft\web\twig\variables\string $type )
$type string The associated element type
return craft\models\FieldLayout The field layout