TWIG template get flexfield field value

Created on 26 March 2023, almost 2 years ago
Updated 27 March 2023, over 1 year ago

For get feld value in template you can use attribute
Example get flex-field field_poster_data>discount>value>33:
{{ dump(content.field_poster_data.0) }}

^ array:3 [▼
  "#theme" => array:2 [▼
    0 => "flexfield"
    1 => "flexfield__field_poster_data"
  ]
  "#field_name" => "field_poster_data"
  "#items" => array:1 [▼
    0 => array:4 [▼
      "name" => "discount"
      "value" => "33"
      "label" => "Discount"
      "label_display" => "above"
    ]
  ]
]

{{ dump(attribute(content.field_poster_data.0, '#items').0.value) }}

"33"

-------------------------

{# Get all subfields of FlexField [field_poster_flexdata] as array #}
	{% if content.field_poster_flexdata %}{% set fieldFlexData_values = [] %}
		{% set fieldFlexDataArr = attribute(content.field_poster_flexdata.0, '#items') %}{#{ dump(fieldFlexDataArr) }#}
		{% for value in fieldFlexDataArr %}{#{ dump(value) }#}
			{% set fieldFlexData_values = fieldFlexData_values|merge({ (value.name):{'label':value.label,'value':value.value} }) %}{#{ dump(fieldFlexData_values) }#}
		{% endfor %}{{ dump(fieldFlexData_values) }}
	{% endif %}
💬 Support request
Status

Active

Version

2.0

Component

Documentation

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024