I have a page where written articles are displayed. The following is a article written by Canada_Girl1993.

enter image description here

As you can see, the author of the article is displayed at the top.

Now, other users are able to comment on this article, as well as the author of the article. But how can I check if a comment is from the author of the article, so that I can add some styling or html to it?

enter image description here

  • 1
    Within a Comment, can you fetch the host entity (I assume Node), and get the author off of that and compare UID to comment UID? – Kevin Oct 12 '17 at 15:46

Actually, before you write any code... D8 automatically adds a 'by-[entity-type]-author'(e.g. by-node-author) class to the <article> tag of each comment, if commenter and author are the same.
This is defined at line 73, in comment.html.twig file(at least this is the case in Bartik theme file), so please take advantage of it :)

  • Wow, didn't know it could be so simple. Totally missed that! Thank you!! – Rubenxfd Oct 13 '17 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.