I have a basic template node--some-name.html.twig, which I am trying to access a specific value from a child of the content variable.
{% for item in content %}
{{ kint(item) }}
{% endfor %}
which prints an expected value like so (trimmed for brevity):
Array
(
[#title] => Body
[#language] => en
[#field_name] => body
[#field_type] => text_with_summary
[#field_translatable] => 1
[#entity_type] => node
[#object] => stdClass Object
(
[__CLASS__] => Drupal\node\Entity\Node
[in_preview] =>
[values:protected] => Array
(
[body] => Array
(
[x-default] => Array
(
[0] => Array
(
[value] => Body sample goes here
[summary] => summary sample here
[format] => rich_text
)
)
)
)
)
)
but if I try to print them in my loop it only returns null... am I missing something super basic?
{% for item in content %}
{{ item["#object"].values.body[0].value }}
{{ item["#object"]["values"]["body"][0].value }}
{% endfor %}
printing {{item}} gives the entire item as expected but trying to access specific deeper properties of item seems to be null regardless of property or how I've accessed it.
Any help would be appreciated.
The property
valuesin your class is protected, meaningtwigwill not be able to access this property unless:valuespublicgetValuesin your classAs seen in the documentation