templates/blog/single_post.html.twig line 1

Open in your IDE?
  1. {% extends  'nav.html.twig' %}
  2. {% block content %}
  3.     <div id="blogSinglePostContentContainer">
  4.         <section id="blogSinglePostContentSection">
  5.             <div class="container" style="padding: 6rem 0 0 0">
  6.                 <h2 style="margin-bottom: 0"> {{ post.title }}</h2>
  7.                 <h6 class="text-secondary">{{ post.createdAt|date('d.m.y') }}</h6>
  8.                 <p style="word-wrap: break-word;">{{ post.content|nl2br }}</p>
  9.                 {% if post.imagePath is not null %}
  10.                     <div class="d-flex justify-content-center">
  11.                         <img src="/assets/images/{{ post.imagePath }}" style="max-width: 500px; height: auto; min-width: 400px">
  12.                     </div>
  13.                 {% endif %}
  14.             </div>
  15.         </section>
  16.         {% if comments is not empty or app.user%}
  17.             <section id="blogSinglePostCommentsSection">
  18.                 <div class="container">
  19.                     {% for comment in comments %}
  20.                         {% if loop.first %}
  21.                             <h3>
  22.                                Комментариев: {{ comments|length }}
  23.                             </h3>
  24.                         {% endif %}
  25.                         <div class="my-4 d-flex" id="comment" style="position: relative">
  26.                             {% if comment.user.iconPath %}
  27.                                 <img class="avatar mr-3 rounded-circle" src="/assets/images/icons/{{ comment.user.iconPath }}" alt="avatar">
  28.                             {% else %}
  29.                                 <img class="avatar mr-3 rounded-circle" src="/assets/images/icons/iconProfile.png" alt="avatar">
  30.                             {% endif %}
  31.                             <div>
  32.                                 <div class="mb-2">
  33.                                     <h5 class="m-0">{{ comment.user.name }} {{ comment.user.lastname }}</h5>
  34.                                     <span class="me-3 small">{{ comment.createdAt|date('d.m.y H:i') }}</span>
  35.                                 </div>
  36.                                 <p> {{ comment.content}} </p>
  37.                             </div>
  38.                         </div>
  39.                     {% endfor %}
  40.                 {% endif %}
  41.                 {% if app.user %}
  42.                     <div>
  43.                         <h3>Оставить комментарий</h3>
  44.                         <form class="row g-3 mt-2" id="singlePostCommentForm">
  45.                             <div class="col-12">
  46.                                 <label class="form-label">Комментарий</label>
  47.                                 <textarea class="form-control" name="addComment[text]" rows="3" style="resize: none" ></textarea>
  48.                             </div>
  49.                             <div class="col-12">
  50.                                 <button type="button" class="btn btn-primary" onclick="sunbmitCommentForm()">Оставить комментарий</button>
  51.                             </div>
  52.                             <input type="text" name="addComment[userId]" style="display: none" value="{{ app.user.id }}">
  53.                             <input type="text" name="addComment[postId]" style="display: none" value="{{ post.id }}">
  54.                         </form>
  55.                     </div>
  56.                 {% endif %}
  57.             </div>
  58.         </section>
  59.     </div>
  60. {% endblock %}
  61. {% block pagescripts %}
  62.     <script>
  63.         /**
  64.          * Отправляет данные с формы добавления комментария на сервер
  65.          */
  66.         function sunbmitCommentForm() {
  67.             event.preventDefault();
  68.             let form = document.getElementById('singlePostCommentForm');
  69.             let formaData = new FormData(form);
  70.             let url = '/blog/addComment'
  71.             sendPostRequest(url, formaData)
  72.                 .then(function () {
  73.                     location.reload()
  74.                 })
  75.         }
  76.     </script>
  77. {% endblock %}