2

new to d8. I have a result page where I need to print the field values of a paragraph field into my controller. The paragraph field is called field_classrooms.

text values print fine for example
{{ teacher.field_last_name.value }}

but when I need to print
{{ teacher.field_classrooms.value }}

I get

User error: "target_id" is an invalid render array key in Drupal\Core\Render\Element::children() (line 97 of core/lib/Drupal/Core/Render/Element.php).

  • have you tried {{ teacher.field_classrooms|raw}} Also what spits out when you do {{ dump(teacher.field_classrooms)}} ? – Matt Sep 26 '16 at 19:00
  • Exception: Object of type Drupal\entity_reference_revisions\EntityReferenceRevisionsFieldItemList cannot be printed and the dump just gives me the wsod – Brittany Sep 26 '16 at 19:05
  • What is the field type of field_classrooms? – Matt Sep 26 '16 at 19:10
  • it is a paragraph reference, but the field type is Entity reference revisions – Brittany Sep 26 '16 at 19:14
  • Also can you share the code where you're declaring the field_classrooms – Matt Sep 26 '16 at 19:14
4

You have to get the paragraph entity with .entity

{{ teacher.field_classrooms.entity.field_in_paragraph.value }}

where you can get the fields inside of the paragraph.

  • Thank you! Is there a way to print all of the fields in the entity, without writing out each one? – Brittany Sep 26 '16 at 19:38
  • I don't know exactly in what kind of twig you are, but usually you should let the paragraph render by itself. If there is a problem with that, ask another question with more details. – 4k4 Sep 26 '16 at 19:50
  • there are multiple fields in the classrooms entity. I want to print all of them rather than typing each out. like so: {{ teacher.field_classrooms.entity.field_in_paragraph.value }} I was hoping to do something more along the lines {{ teacher.field_classrooms.entity.value }} – Brittany Sep 26 '16 at 20:00
  • It should do this.. otherwise there could be something about your setup that you aren't sharing. – Kevin Sep 26 '16 at 22:47
0

I came accross the same issue while trying to add paragraph field content manual in simplenews email twig template

I too did not find a way to use one twig statement so i used a loop...

Check how many values we have in paragraph

{{ teacher.field_classrooms|length }}

Getting 1st value of paragraph field

{{ teacher.field_classrooms[0].entity.field_in_paragraph.value }}

And this is how I used it finally: Loop trough paragraph items

{% for entity in teacher.field_classrooms %} {{ teacher.field_classrooms[loop.index0].entity.field_in_paragraph.value }} {% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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