Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image size based on Forloop pattern

I have a loop of images.

Desired pattern:

1   4  5   8  9      12  13      16
 2 3    6 7     10 11      14 15

Based the forloop number, I will have 2 possible image sizes, the ones on top will be size 1 and the ones on the bottom will be size 2.

So I used divisibleby:"x" to start with, but soon realised that this wont work, as the pattern does not always allow divisibleby, and in some cases both might be true.

I could litteraly do this manualy to check if the number is in a list, like :

[2,3,6,7,14,15....]

But this would be really dumb.

Are there a simple way to do this?

My original idea, that is not valid at all!

{% for project in branding %}
    {% if forloop.counter == 1 or forloop.counter|divisibleby:"4" or forloop.counter|divisibleby:"5" %}
        <div class="tile">
            <a href="/work/{{ project.slug }}/">
                <img src="{% thumbnail project.tile_image "313x490" crop="center" as im %}{{ im.url }}{% endthumbnail %}">
            </a>
        </div>
    {% endif %}
    {% if forloop.counter|divisibleby:"2" or forloop.counter|divisibleby:"3" %}
        <div class="tile">
            <a href="/work/{{ project.slug }}/">
                <img src="{% thumbnail project.tile_image "313x310" crop="center" as im %}{{ im.url }}{% endthumbnail %}">
            </a>
        </div>
    {% endif %}
{% endfor %}
like image 807
Harry Avatar asked Jun 02 '26 23:06

Harry


1 Answers

I believe that you are looking for cases where your number mod 4 is either 2 or 3.

2 % 4 = 2
3 % 4 = 3
6 % 4 = 2
7 % 4 = 3
10 % 4 = 2
11 % 4 = 3
like image 106
emcallaway Avatar answered Jun 04 '26 11:06

emcallaway



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!