3

I am trying to develop a loop in a craft template that adjust the numbers of rows and awards per row based on the total number of awards. The numbers are all coming back correct but I am struggling with getting the syntax of the loop correct. Below is the type of loop I am trying to execute.

for ($i = 1; ; $i++) {
if ($i > 10) {
  break;
}
  echo $i;
}

But I am getting errors because my syntax is not correct and I cannot seem to find this, although I realize I am probably either just missing it somewhere or not recognizing it.

I was trying something like this, along with other variations, but it keeps throwing errors.

{% set exactRowsNeeded = count / 7 %} <!-- correct -->
{% set rows = ceil(exactRowsNeeded) %} <!-- correct -->
{% set exactAwardsPerRow = count / rows %} <!-- correct -->
{% set awardsPerRow = ceil(exactAwardsPerRow) %} <!-- correct -->

{% set r = 1 %}
{% for r %}
{% if r <= 2 %} 
  {{ r }}
{% set r = r++ %}
{% endif %}
{% endfor %}

Here throws an error at the "for r" line. It seems to be looking for something like "for r in rows" or something. Even just a link to an example would be awesome I just cannot seem to get this syntax correct.

2

The code below ended up solving the issue for me.

{% for row in 0..rows %}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.