0

how to personalize my comments ?

  • I want to display since when the comment was created instead of the date.

  • I want to display the comment ID with the link "permalink".

Can you help me ? Thank you

comment--field-article-commentaire.html.twig :

<article{{ attributes.addClass('js-comment comment--field-article-commentaire') }}>
  <div class="row card rounded-lg mt-4">
    <div class="card-header p-2 m-0 h6">
      <div class="media">
        <div class="timeline-icon mt-1 mr-3 mb-1 ml-1 float-left">
          {{ drupal_entity('user', comment.uid.target_id, 'comment') }}
        </div>
        <div class="media-body">
          <div class="mb-2">
            {{ permalink }}
          </div>
          <div class="mb-2">
            {{ author }}
          </div>
          <div class="mb-0">
            le {{ created }}
          </div>
        </div>
      </div>
    </div>
    <div class="card-body p-2">
      {{ content.field_article_commentaire }}
    </div>
    <div class="card-footer d-flex flex-wrap justify-content-start pt-0">
      <div class="mt-3 mr-3">
        {{ content.flag_report_comment }}
      </div>
      <div class="mt-3 mr-3">
        {{ content.links }}
      </div>
    </div>
  </div>
</article>

Here is the current view of my comments :

https://ibb.co/QF051yV

I would like to display the date like this :

https://ibb.co/QCQbmG2

1

Twig's date extension does exactly what you ask:

{{ created | time_diff }}

However, this extension isn't in Drupal by default, assuming you're using Composer you need to add this extension to your project by running:

composer require twig/extensions

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.