Blog Archives

Joining Strings in a Drupal Views Field using Twig

I have two optional fields on a Drupal 8 content type: City and State. Both are rendered as simple text. In a fields-based View I wanted to show the field output as “Portland” or “Portland, OR”, or “OR”. First, I added the two

Tagged with: , , ,
Posted in 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

Tagged with: , ,
Posted in Development

Drupal 8 – Formatting a Date Field in Twig

Here are the four easiest ways I’ve found to show dates via Twig inside of a node template. They all result in the same output. Use the field’s formatter settings; include wrappers

This is the only example that includes wrappers.

Tagged with: , ,
Posted in Development