Dataobjekt News Bootstrap Left / Right Repeat

Hi there.

We have a simple left-right news section with BS4 (see screenshot).
We would like to fill theese news with data objects.

Whats the best way that pimcore 1 time takes the image left and next time image right to keep order?

Thanks in advance!

Hi @sandra-walker,

With Twig this would be really simple:

{% for post in news %}
        {% if loop.index is odd %}
            <!-- Place image on the left -->
        {% else %}
            <!-- Place image on the right-->
        {% endif %}
{% endfor %}

With PHP you can determine if a number is even or odd with the modulus operator.

if (($number % 2) === 0) {
    // The number is even
} else {
    // The number is odd

Another good reason to switch to Twig. :wink:

Hope this helps!

It worked. Thanks!

@aarongerig … isch ja guet, luege s twig mal ah =)

1 Like