2

Im working on the comment section of my page and found a useful website with this https://blog.miguelgrinberg.com/post/implementing-user-comments-with-sqlalchemy. The problem i am having is representing the comments on the website. How to i display nested comments in the same manner as shown in the link above using the flask code below.

for comment in Comment.query.order_by(Comment.path):
    print('{}{}: {}'.format('  ' * comment.level(), comment.author, comment.text))

In other words: how would the above segment look as jinja code.

{% for comment in comments %]
          .
          .
          .
{% endfor %}

If there is another way to do it, i'm all ears. Thanks.

High Roller
  • 67
  • 2
  • 16

1 Answers1

3

Here i am after some research and successful completion of my comment section to answer my own question. To get this effect do this below

{% for comment in all_comments %}
                        <div class="row">
                            {% if comment.comment_level == 0 %}
                                <div class="col-lg-12 ">
                            {% elif comment.comment_level == 1 %}
                                <div class="col-lg-1 "></div>
                                <div class="col-lg-11">
                            {% elif comment.comment_level == 2 %}
                                <div class="col-lg-2 c"></div>
                                <div class="col-lg-10 ">
                            {% elif comment.comment_level == 3 %}
                                <div class="col-lg-3 "></div>
                                <div class="col-lg-9 ">
                            {% else %}
                                <div class="col-lg-4 "></div>
                                <div class="col-lg-8 ">
                            {% endif %}
                                 <div>
                                     <p>{{comment.text}}</p>
                                 </div>

This will create the step ladder effect you see in comment section. This is a flask solution. I'm sure you can replicate it in other languages.

High Roller
  • 67
  • 2
  • 16