Skip to content

Instantly share code, notes, and snippets.

@plepe
Created September 25, 2023 11:36
Show Gist options
  • Select an option

  • Save plepe/c860cc2f9f5d2d8d4ea35e3a31a09f91 to your computer and use it in GitHub Desktop.

Select an option

Save plepe/c860cc2f9f5d2d8d4ea35e3a31a09f91 to your computer and use it in GitHub Desktop.

Revisions

  1. plepe created this gist Sep 25, 2023.
    18 changes: 18 additions & 0 deletions display_suite_twig.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    I couldn't find any documentation about Twig Fields using Display Suite, so I decided to create one on my own. You are very welcome to add more information.

    Adding a Twig field in Drupal Display Suite, you can use the following syntaxes:

    Render the ID of the current entity:
    ```twig
    {{ entity.id }}
    ```

    Render the value of a text field (called 'Foo'):
    ```twig
    {{ entity.field_foo[0].value }}
    ```

    This does not work (it will only generate "`{}`"):
    ```twig
    {{ entity.field_foo|json_encode }}
    ```