0

in my node type template, how do I display alternate text if comments are closed for the node ?

  {% if content.comment %}
    <div class="card mb-5 p-3 shadow">
      {{ content.comment }}
    </div>
  {% else %}
    <div class="card mb-5 p-3 shadow">
      {{ content.field_link }}
      {{ content.field_code }}
    </div>
  {% endif %}

EXAMPLE

If comments are open :

{{ content.comment }}

If comments are closed :

TEXT

1 Answer 1

1

Assuming you're using the default field definitions installed by the standard profile, what you want is the status property of the comment field of the node, which is accessible in twig via node.comment.status.

{% if node.comment.status == 2 %}
   {# comments are open #}
{% elseif node.comment.status == 1 %}
   {# comments are closed & visible #}
{% elseif node.comment.status == 0 %}
   {# comments are closed & hidden #}
{% endif %}
1
  • Thanks it works
    – user98390
    Mar 11, 2020 at 20:21

Your Answer

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