comment.twig 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. {% if comments[parent_id] %}
  2. {% for comment in comments[parent_id] %}
  3. {# The id="" is used as anchor #}
  4. <div class="comment" style="margin-left:{{ depth * 2 }}em" id="comment-{{ comment.hashId }}">
  5. <div class="pin">◉</div>
  6. <div class="info">
  7. {# Username #}
  8. <span class="username {{ post.userId == comment.userId ? 'op' }}">
  9. <a href="{{ ('user/' ~ comment.username|url_encode)|docroot }}">{{ comment.username }}</a>
  10. </span>
  11. {%
  12. include 'vote.twig' with {
  13. target: 'comment',
  14. hash_id: comment.hashId,
  15. vote: votes[comment.id] is defined ? votes[comment.id].vote : null,
  16. vote_count: comment.vote,
  17. user: user is defined ? user : null
  18. } only
  19. %}
  20. {# DateTime #}
  21. <a href="{{ ('post/' ~ post.hashId ~ '#comment-' ~ comment.hashId)|docroot }}"><em>{{ comment.created|ago }}</em></a>
  22. {% if user %}
  23. {# Reply #}
  24. <a href="../reply?comment={{ comment.hashId }}">Reply</a>
  25. {% if comment.userId == user.id %}
  26. {# Edit #}
  27. <a href="../edit?comment={{ comment.hashId }}">Edit</a>
  28. {% endif %}
  29. {% endif %}
  30. </div>
  31. <div class="text">
  32. {{ comment.text|markdown|raw }}
  33. </div>
  34. </div>
  35. {# Add replies #}
  36. {% include 'comment.twig' with {
  37. 'post': post,
  38. 'comments': comments,
  39. 'votes': votes,
  40. 'parent_id': comment.id,
  41. 'depth': depth + 1
  42. } %}
  43. {% endfor %}
  44. {% endif %}