0

I can print the result object by {{ dump(item.value['#result']) }} in theme item-list--search-results.html.twig template file.

enter image description here

I want to print the body field value("body"=>"value") from the object.

How I will do ? I have tried some other ways which I know

  • {{ dump(item.value['#result']['node'].#values['body'][0]['value']) }}
  • {{ dump(item.value['#result']['node']['#values']['body'][0]['value']) }}
0

1 Answer 1

3

For normal fields you can get the field value by appending the property name .value:

{% set node = item.value['#result']['node'] %}

{{ node.field_foo.value }}

For the body field you need an extra step to process the stored text format:

{{ {
  '#type': 'processed_text',
  '#text': node.body.value,
  '#format': node.body.format,
} }}
1

Not the answer you're looking for? Browse other questions tagged or ask your own question.