Fieldset

Fieldset

{{ fieldset }}

A group of fields which together define a custom object. May either define a single object or a list of objects.

Properties of {{ fieldset }} objects
Name Type Description
is_valid Boolean True if there is at least one custom object
value String The same as what you would see when inspecting this object. For fieldset fields you do not typically care about this - use objects or fields instead
allow_multiple Boolean True if the fieldset allows multiple objects to be entered. Changes the way some of the other fieldset properties work
objects list A list of custom data objects defined by this fieldset. Only if allow_multiple is true
fields list A single custom data object defined by this fieldset. Only if allow_multiple is false
field_id String The identifier for this field
label String The label for this field
output String Same as value. May include additional markup in the editor preview to make it easier to edit content

Field containing either a single custom object or multiple custom objects - depending on whether allow_multiple is true. You may also treat this object as a list containing all of the child objects (if allow_multiple is true) or fields (if allow_multiple is false) which may be iterated using a {% for %} loop. For more details see the examples below: If allow_multiple is false, individual fields may be accessed using the {{ object.keyName }}, {{ object["keyName"] }}, {{ object.fields.keyName }}, or object.fields["keyName"] syntax. You may also treat this object as a list containing all of the fields which may be iterated using a {% for %} loop. For more details, see the examples below:

Related

object

May be any object, including simple, complex and list objects. In some cases may even include symbols and null.

{{ data }}

Object containing information about custom fields or other extended data outside of the core properties of an object.

list

An enumerable list containing zero or more objects. Lists may contain many different object types, although most lists only contain a single object type. There are a large number of other complex object types that are also lists (ag: an articlelist is a complex object but is also a list of article objects).

boolean

True or False

Examples

Demonstrates how to reference a fieldset field in 5 different ways. These examples assume that the fieldset does not allow multiple objects. If the fieldset allows multiple objects, you would need to reference entity.fieldset[0] instead of entity.fieldset.

5 Ways to Reference a Fieldset Field

Copy

Reference as a property

{% if entity.fieldset.field1.is_valid %}
<p>Field 1 Value: {{entity.fieldset.field1}}</p>
{% endif %}

Reference as a dictionary key

{% if entity.fieldset['field2'].is_valid %}
<p>Field 2 Value: {{entity.fieldset['field2']}}</p>
{% endif %}

Reference as a property of the fields object

{% if entity.fieldset.fields.field3.is_valid %}
<p>Field 3 Value: {{entity.fieldset.fields.field3}}</p>
{% endif %}

Reference as a dictionary key of the fields object

{% if entity.fieldset.fields['field4'].is_valid %}
<p>Field 4 Value: {{entity.fieldset.fields['field4']}}</p>
{% endif %}

List all fieldset fields

<ul>
{% for field in entity.fieldset %}
<li><strong>{{ field.field_id }}</strong> = {{ field.value }}</li>
{% endfor %}
</ul>
Output an unordered list containing all of the fieldset fields and their values.

Demonstrates how to list all objects in a fieldset field.

List all objects in a fieldset field

Copy
{% if entity.fieldset.is_valid and entity.fieldset.allow_multiple %}
<ul>
{% for object in entity.fieldset %} --equivalent to {% for object in entity.fieldset.objects %}
<li><strong>{{ object.custom_title }}</strong>{% if object.custom_description.is_valid %}<br />
{{ object.custom_description }}{% endif %}</li>
{% endfor %}
</ul>
{% endif %}

Demonstrates how to list all values in a fieldset field.

List all values in a fieldset field

Copy
{% if entity.fieldset.is_valid %}
{% unless entity.fieldset.allow_multiple %}
<ul>
{% for field in entity.fieldset %} --equivalent to {% for field in entity.fieldset.fields %}
<li><strong>{{field.field_id}}</strong> = {{field.output}}</li>
{% endfor %}
</ul>
{% endunless %}
{% endif %}