Open bobbingwide opened 1 year ago
Example with one layout labelled Layout 1 (layout_1
) that contains a text field called flexible_content_text
.
[layouts] => Array
[layout_64896c6264a66] => Array
[key] => (string) "layout_64896c6264a66"
[name] => (string) "layout_1"
[label] => (string) "Layout 1"
[display] => (string) "row"
[sub_fields] => Array
[0] => Array
[ID] => (integer) 420
[key] => (string) "field_64896c7faa275"
[label] => (string) "Flexible Content Text"
[name] => (string) "flexible_content_text"
[aria-label] => (string) ""
[prefix] => (string) "acf"
[type] => (string) "text"
[value] => (NULL)
[menu_order] => (integer) 0
[instructions] => (string) ""
[required] => (integer) 0
[id] => (string) ""
[class] => (string) ""
[conditional_logic] => (integer) 0
[parent] => (integer) 419
[wrapper] => *RECURSION* wrapper 0
[parent_layout] => (string) "layout_64896c6264a66"
[default_value] => (string) "FCT"
[maxlength] => (string) ""
[placeholder] => (string) ""
[prepend] => (string) ""
[append] => (string) ""
[_name] => (string) "flexible_content_text"
[_valid] => (integer) 1
[min] => (string) ""
[max] => (string) ""
The value of $field
is an array of the sections. The first item in each section is the name of the layout to use to display the section acf_fc_layout
. The subsequent items are the values of the fields in that section/layout.
Array
[0] => Array
[acf_fc_layout] => (string) "layout_1"
[flexible_content_text] => (string) "FCT 1"
[1] => Array
[acf_fc_layout] => (string) "layout_1"
[flexible_content_text] => (string) "FCT 2"
In the prototype for this block's output we'll render each section as a div with a classname of the selected layout ( acf_fc_layout
) then render each of the sub_fields
in the layout, obtaining the values for the field from the section's array.
The
flexible_content
field type is similar to therepeater
field type.You need to define one or more
layouts
in order for the Add Row button to display the layout type you want to add.The field_info structure contains
layouts
which is a multi-dimensional associative array of layout arrays which contain an array ofsub_fields
within the layout.