logo

Palette - Make it Colorful🎨

Palette - Visual Page Builder, no design degree required.

Live Demo Download Palette

Scroll

Hide the comment field

12/07/2025, by Ivan
Forums

Good day!

I need to hide a specific comment field from all users except the node author.

The idea is as follows: User1 creates a certain content type Article, and a separate comment type with a set of fields is created for this content type. Other users write comments on this content, filling in several fields. When viewing comments on the content created by User1, only User1 sees all the comment fields, while the other users see all fields except "field_example".

I overrode the comment.html.twig template.

I'm trying to add this condition:

{% if node.author_name = user.username %}
  {{ content }}
  {% else %}
  {{ content|without('field_example') }}
  {% endif %}

But it throws an error.

Please advise what I’m doing wrong!

Thanks a lot in advance!