1

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
  • 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
    Commented Oct 12, 2017 at 15:46

1 Answer 1

1

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 :)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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