Accessing subfield data in twig

16 May, 2024

You have a compound field with subfields (like the body field) and want to access a subfield in twig? Not a problem.

Let's say your field is field_mystuff and the subfield is url. In twig, you would access it like this:

{{ content.field_mystuff.url }}

 

  • tip icon. tip
  • D9

    /themes/custom/tac/images/tag-icons/d9-logo.svg
    Drupal 9
    Drupal 9

    D8

    /themes/custom/tac/images/tag-icons/d8-logo.svg
    Drupal 8
    Drupal 8

Login or Register to Comment!