Problem/Motivation

Its not possible to print out the number of comments that are written for a node.
{{content.comment['#items'].comment_count}} is available when a node is viewed in page mode, but not in teaser mode

Proposed resolution

create a variable {{ node.comment_count }} thats available both in teaser & page

Remaining tasks

User interface changes

API changes

Data model changes

Comments

mortendk created an issue. See original summary.

dawehner’s picture

Well, what you can do is {{node.field_comment.comment_count}} which is the only logical thing if you have mulitple comment types.
Are you sure that doesn't work?

aburrows’s picture

@dawahner I can make it so it displays as {{ node.comment_count }}, are we agreed on that?

mortendk’s picture

@dawehner yup i tested n tested again + it came up during badcamp, where we also tested it

kint( {{node.field_comment.comment_count}} ) gives me a null in a node.html.twig

and for the record the number of comments is printed out in the link template, but thats a complete cluster to get through

larowlan’s picture

We can't use a single property, there could be more than one comment field

dawehner’s picture

@dawehner yup i tested n tested again + it came up during badcamp, where we also tested it

Haters gonna hate, I give an atom about them, and this was a clear instance of that.

What actually works is {{ node.comment.comment_count }} because 'comment' is the fieldname by default.

larowlan’s picture

What actually works is {{ node.comment.comment_count }} because 'comment' is the fieldname by default.

That sounds like a closed works as designed to me

Berdir’s picture

Status: Active » Closed (works as designed)

Yes, I think so. That's exactly how you access that information, through the field property.

drase15’s picture

thanks #6 works
just a heads up, "comment" is the machine name of your "comment type", not the field machine name.
so if you use another comment type just replace it for that machine name and you are ready to go