Image size based on Forloop template

I have an image loop.

Desired template:

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

      

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

So, I used divisibleby: "x" to start with, but I soon realized that it didn't work as the template doesn't always allow for sharing, and in some cases both can be true.

I could do it manually to check if the number is in the list, for example:

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

      

But that would be really stupid.

Is there an easy way to do this?

My original idea which 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 %}

      

+3


source to share


2 answers


This looks like a tag for cycle

inline template tag to me:

{% for project in branding %}
    <div class="tile">
      {% cycle '313x490' '313x310' '313x310' '313x490' as size silent %}
      <a href="/work/{{ project.slug }}/">
        <img src="{% thumbnail project.tile_image size crop="center" as im %}{{ im.url }}{% endthumbnail %}">
      </a>
    </div>
{% endfor %}

      



But I am not familiar with the tag thumbnail

you are using, so there might be complexity there.

+3


source


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



2 % 4 = 2
3 % 4 = 3
6 % 4 = 2
7 % 4 = 3
10 % 4 = 2
11 % 4 = 3

      

+5


source







All Articles