I have a field_slides paragraph field on my home page, on drupal 9.1.3. It is for rendering a carousel. I want to iterate over the elements of the paragraph field (eg the slides with title, description and button fields). I'm using drupal_field twig tweak function for the sake of translability. I have tried something like the following :

  {%  for slide in element['#items'] %}
     <div class="carousel-item {% if loop.index0 == 0 %}active{% endif %}">
     <img class="d-block w-100" src="{{ file_url(slide.entity.field_illustration[0].entity.fileuri) }}" alt="First slide">
     <div class="carousel-caption d-md-block w-50">
     <h5 class="carousel-title" onload="animateCarouselTitle(ev)">{{ drupal_field('field_titre', 'node', {{ slide.entity.nid }}) }}</h5>
     <p class="carousel-bouton">{{ drupal_field('field_bouton', 'node', {{ slide.entity.nid }}) }}</p>
     <p>{{ drupal_field('field_corps', 'node', {{ slide.entity.nid }}) }}</p>
   {% endfor %}

Any idea on how to dynamically get the nid of the paragraph entity in the drupal_field function?

  • In Drupal 9 nodes are identified by "id" key, not by "nid".
    – ya.teck
    Commented Feb 3, 2021 at 4:13
  • Are you per chance looking for the paragraph id or are you truly looking for NID, i.e. the node id which as above commenter mentions is now id in D8 & 9. Commented Feb 13, 2021 at 22:29

1 Answer 1


Try taking away the curly brackets from around {{ slide.entity.nid }} so it's:

{{ drupal_field('field_corps', 'node', slide.entity.id) }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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