• Development

    Drupal + Twig: Render Taxonomy Terms and Comma-Separated List

    Here’s a snippet that renders the terms in a multi-value taxonomy reference field (in a node template) as plain text items separated by commas. Yes, you could get the string into the desired format using PHP, but I wanted to try to do it with only Twig. The result is moderately readable.

    Twig Code:

    For a taxonomy term reference field called field_pub_tr_res_committees

    Output:

    If 1 value: My first term