Comment Counts in Twig

Views makes it easy to include a node's comment count as a field, but what about when you aren't using fields...when you display content, instead?

You could write a preprocess function, but why code when you don't have to? Use twig!

The comment class includes a method count(), but that method is not exposed to twig. Luckily, an alternative is:

{{ node.comment.comment_count }}

That's all there is to it!


Of course, the Drupal Community isn't the only place to give back. It's a complex world, and there are as many worthy causes as their are melodies, with most being served by multiple charitable organizations. Here are a few of those that strike a 7th chord with me.