Fields

Type
Class
Namespace
craft\web\twig\variables
Inherits
craft\web\twig\variables\Fields
Since
3.0
Deprecated in
in 3.0

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

View source

Public Methods

MethodDescription
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

Returns

string[] – The available field type classes

Signature

public string[] getAllFieldTypes ( )

getAllFields()

Returns all fields.

View source

Arguments

  • $indexBy (string, null) – The attribute to index the fields by

Returns

craft\base\FieldInterface[] – The fields

Signature

public craft\base\FieldInterface[] getAllFields ( \craft\web\twig\variables\string $indexBy = null )

getAllGroups()

Returns all field groups.

View source

Arguments

  • $indexBy (string, null) – The attribute to index the field groups by

Returns

craft\models\FieldGroup[] – The field groups

Signature

public craft\models\FieldGroup[] getAllGroups ( \craft\web\twig\variables\string $indexBy = null )

getFieldByHandle()

Returns a field by its handle.

View source

Arguments

  • $handle (string) – The field’s handle

Returns

craft\base\FieldInterface, null – The field, or null if it doesn’t exist

Signature

public craft\base\FieldInterface, null getFieldByHandle ( \craft\web\twig\variables\string $handle )

getFieldById()

Returns a field by its ID.

View source

Arguments

  • $fieldId (integer) – The field’s ID

Returns

craft\base\FieldInterface, null – The field, or null if it doesn’t exist

Signature

public craft\base\FieldInterface, null getFieldById ( \craft\web\twig\variables\int $fieldId )

getFieldsByGroupId()

Returns all the fields in a given group.

View source

Arguments

  • $groupId (integer) – The field group’s ID
  • $indexBy (string, null) – The attribute to index the fields by

Returns

craft\base\FieldInterface[] – The fields

Signature

public craft\base\FieldInterface[] getFieldsByGroupId ( \craft\web\twig\variables\int $groupId, \craft\web\twig\variables\string $indexBy = null )

getGroupById()

Returns a field group by its ID.

View source

Arguments

  • $groupId (integer) – The field group’s ID

Returns

craft\models\FieldGroup, null – The field group, or null if it doesn’t exist

Signature

public craft\models\FieldGroup, null getGroupById ( \craft\web\twig\variables\int $groupId )

getLayoutById()

Returns a field layout by its ID.

View source

Arguments

  • $layoutId (integer) – The field layout’s ID

Returns

craft\models\FieldLayout, null – The field layout, or null if it doesn’t exist

Signature

public craft\models\FieldLayout, null getLayoutById ( \craft\web\twig\variables\int $layoutId )

getLayoutByType()

Returns a field layout by its associated element type.

View source

Arguments

  • $type (string) – The associated element type

Returns

craft\models\FieldLayout – The field layout

Signature

public craft\models\FieldLayout getLayoutByType ( \craft\web\twig\variables\string $type )