templates/comments.html.twig line 1

Open in your IDE?
  1. <section class="comments-section mt-4 mb-4" id="comments" style="text-align: left; max-width: 700px; margin-left: auto; margin-right: auto;">
  2.     <h3 class="text-white mb-3">
  3.         Comments
  4.         {% if comments|length > 0 %}
  5.             <span class="badge bg-secondary">{{ comments|length }}</span>
  6.         {% endif %}
  7.     </h3>
  8.     {% for message in app.flashes('comment') %}
  9.         <div class="alert alert-success alert-dismissible fade show" role="alert">
  10.             {{ message }}
  11.             <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  12.         </div>
  13.     {% endfor %}
  14.     {% if app.user %}
  15.         <div class="mb-4 p-3 rounded" style="background: rgba(255,255,255,0.05);">
  16.             {{ form_start(formComment) }}
  17.             <div style="width: 100%;">
  18.                 {{ form_widget(formComment.comment, {'attr': {'class': 'form-control bg-dark text-white border-secondary comment-form-textarea mb-2', 'placeholder': 'Write a comment...', 'rows': '2', 'style': 'width: 100%;'}}) }}
  19.                 {{ form_errors(formComment.comment) }}
  20.             </div>
  21.             <div class="d-flex align-items-center gap-2 flex-wrap">
  22.                 {{ form_widget(formComment.captcha) }}
  23.                 {{ form_widget(formComment.submit, {'attr': {'class': 'btn btn-primary btn-sm ms-auto'}}) }}
  24.             </div>
  25.             {{ form_end(formComment) }}
  26.         </div>
  27.     {% else %}
  28.         <p class="mb-4">
  29.             <a href="{{ path('security_login') }}" class="btn btn-outline-light btn-sm">Log in to leave a comment</a>
  30.         </p>
  31.     {% endif %}
  32.     {% if comments|length > 0 %}
  33.         {% for comment in comments %}
  34.             <div class="d-flex gap-2 mb-3 pb-3 {% if not loop.last %}border-bottom border-secondary{% endif %}">
  35.                 <a href="{{ path('user_user', {username: comment.user.username}) }}" title="{{ comment.user.username }}" class="flex-shrink-0">
  36.                     {% if comment.user.picture == 1 %}
  37.                         <img class="rounded-circle" src="{{ asset('images/user/' ~ comment.user.username ~ '.jpg') }}" width="36" height="36" alt="{{ comment.user.username }}"/>
  38.                     {% else %}
  39.                         <picture>
  40.                             <source srcset="{{ asset('images/generic-avatar-comment.webp') }}" type="image/webp">
  41.                             <img class="rounded-circle" src="{{ asset('images/generic-avatar-comment.jpg') }}" width="36" height="36" alt="{{ comment.user.username }}"/>
  42.                         </picture>
  43.                     {% endif %}
  44.                 </a>
  45.                 <div class="flex-grow-1" style="min-width: 0;">
  46.                     <div class="d-flex justify-content-between align-items-center">
  47.                         <div>
  48.                             <a href="{{ path('user_user', {username: comment.user.username}) }}" class="text-white text-decoration-none fw-bold small">{{ comment.user.username }}</a>
  49.                             <small class="text-muted ms-1">{{ comment.createdAt|ago }}</small>
  50.                         </div>
  51.                         {% if app.user == comment.user or is_granted('ROLE_ADMIN') %}
  52.                             <div class="dropdown">
  53.                                 <button class="btn btn-sm btn-link text-muted p-0 comment-dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
  54.                                     <i class="fas fa-ellipsis-v"></i>
  55.                                 </button>
  56.                                 <ul class="dropdown-menu dropdown-menu-dark dropdown-menu-end">
  57.                                     <li><a class="dropdown-item" href="{{ path('user_edit_comment', {id: comment.id}) }}"><i class="fas fa-edit me-2"></i>Edit</a></li>
  58.                                     <li><a class="dropdown-item text-danger" href="{{ path('user_remove_comment', {id: comment.id}) }}" onclick="return confirm('Are you sure you want to delete this comment?');"><i class="fas fa-trash me-2"></i>Delete</a></li>
  59.                                 </ul>
  60.                             </div>
  61.                         {% endif %}
  62.                     </div>
  63.                     <p class="mb-0 mt-1 text-light small">{{ comment.comment|e }}</p>
  64.                 </div>
  65.             </div>
  66.         {% endfor %}
  67.     {% else %}
  68.         <p class="text-muted fst-italic small">No comments yet. Be the first to comment!</p>
  69.     {% endif %}
  70. </section>