Search code examples
phpdrupaltwigdrupal-9

I am unable to get values in twig template in drupal 9


I have mapped the fields of a content type (a webform) to node using Webform content creator in drupal 9 now the issue is that i am not getting those mapped fields in my twig template. All I am getting are previously mapped values. I have double checked the fields in content type and mapping in webform content creator.


Solution

  • You can use Drupal module Devel (https://www.drupal.org/project/devel) to find the right key to display.

    Or debug in twig some of these:

    • {{ content.field_name.0 }}
    • {{ node.field_name.0.target_id }}

    get keys you need:

    {{ dump(content|keys) }}
    

    dump like this for small fields:

    {% for k,v in content.field_name  %}
      - {{ k }}: {{ dump(v.value) }}<br>
    {% endfor %}
    

    the variable content.field_name can be changed if you found the right field from your dump before