Wazy
Wazy

Reputation: 494

Hide title if for statement is is empty

I have an image gallery for each users post. However, if a user has not uploaded any images I don't want to display the title "Image Gallery". How would I go about hiding the title if the for loop does not return anything?

<a>Image Gallery</a>
<div class="row">
    {% for images in postgallery %}
    <div class="col-md-3">
        <a href="{{ images.images.url }}" data-lightbox="image-1">
            <img class="img-thumbnail" src="{{ images.images.url }}" />
        </a>
    </div>
    {% endfor %}
</div>

I have tried a few variations of {% if imagegallery == 0 %} but I can't get anything to work as I would like

Upvotes: 0

Views: 129

Answers (1)

Alireza
Alireza

Reputation: 2123

According to django doc you can use this syntax: {% if postgallery|length == 0 %}

Upvotes: 1

Related Questions