In my comment type, I created a "teaser" view.

When I enable the debug mode in the "service.yml" file, the display modes of the comments do not appear in the suggestions.

Why ?

How to use a different display mode than the default one ?

How to customize the display mode "teaser" with a twig file ?

enter image description here

I created a file named comment--field-article-commentaire--teaser.html.twig

It contains the following code, but it is not rendered

<article{{ attributes.addClass('js-comment comment--field-article-commentaire--teaser') }}>

  test comment


I also created the following file comment--field-article-commentaire.html.twig

It contains the following code. It works, but impossible to use "teaser"

<article{{ attributes.addClass('js-comment comment--field-article-commentaire') }}>

  <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 bs-region-comment">

    <div class="col-xs-3 col-sm-3 col-md-2 col-lg-2 bs-left">
      {{ drupal_entity('user', comment.uid.target_id, 'comment') }}

      <div class="bs-field-status">
       {{ drupal_entity('user', comment.uid.target_id, 'status') }}


    <div class="col-xs-9 col-sm-9 col-md-10 col-lg-10 bs-right">
     <b><i>{{ created }}</i></b>
     {{ content.field_article_commentaire }}
     {{ content.links }}
     {{ content.flag_report_comment }}




I found this :


Pattern: comment--[comment-field-name]--[node-type].html.twig
Base template: comment.html.twig (base location: core/modules/comment/template/comment.html.twig)

There is no explanation for displaying a display mode. However, it is possible to add display modes to the type of comment.

How to use them ?


{{ drupal_entity('comment', content.comment_body['#object'].id, 'teaser') }}

should do the trick.

| improve this answer | |

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.