[Answer]-Nested loops in template

1๐Ÿ‘

You could use {% if forloop.first %} to check if this is the first iteration.

A full list of forloop constructs can be found here:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for

๐Ÿ‘คIon Scerbatiuc

0๐Ÿ‘

{{ forloop.counter }} 

should give you the count of the iteration. If itโ€™s one, you should be dealing with your first element.

๐Ÿ‘คpypat

0๐Ÿ‘

you can add a custom css class for first element

{% for i in prosize %}
  <li {% if forloop.first %}class="red"{% endif %}>
      <a class="order" id="{{i.option1}}">{{i.option1}}</a>
  </li>
{% endfor %}

and css

.red {
  background: red;
}
๐Ÿ‘คBenyasca

Leave a comment