Instance field

The instance field allows a field to hold another template (or schema) allowing you to build nested hierarchies.

myInstanceField:
  type: instance
  schemas:
    - path/to/template-a.twig
    - path/to/template-b.twig

This field definition creates the following input in the control panel:

An instance field in the control panel

Attributes

Property Description
group Starts a new field group.
instructions Additional instructions for this field in the control panel. Will be shown beneath the field label.
label The primary `label` of the input field in the control panel. When omitted, a label will be generated from the name of the field.
rules The validation rules of the field.
schemas Required. A list of all allowed schemas. If multiple schemas are specified, a dropdown will be shown in the control panel.
width The width of the field in the control panel.

schemas

A list of all allowed schemas. If multiple schemas are specified, a dropdown will be shown in the control panel. This can either be a single string or a list of schema names.

schemas:
  - path/to/template-a.twig
  - path/to/template-b.twig

You may use wildcards to include entire directories.

schemas: path/to/*

Templating

You can render the template of the instance field by using the :code:display twig tag.

label: Instance field demo
fields:
  instanceField:
    type: instance
    schemas: blocks/\*
---
{% display instanceField %}

You can also use the html utility function to retrieve the rendered template as a twig html node.

{{ instanceField.html }}

The html utility function allows you to pass additional template variables:

{{ instanceField.html({
  extraValue: 'Some value'
}) }}

The instance contains the full data set of the schema and you can directly access fields defined on the schema:

{{ instanceField.title }}