1

I am creating a template in HTML

{% for product in products %}
    <tr>
        <td>{{ product.id }}</td>
        <td>{{ product.product_name }}</td>
        {% for i in quantities %}
            {% if forloop.counter == forloop.parentloop.counter %}
                <td id="q1">{{ i }}</td>
            {% endif %}
        {% endfor %}

 {% endfor %}

How can I assign a different id to each item in quantities? Can I use .format just like we do in python?

1
  • What do you mean by each item? td's id attribute? Which id do you want to assign? Product id? quantity number? Commented Oct 2, 2019 at 5:29

1 Answer 1

2

Like this?

    {% for i in quantities %}
        <td id="q{{ forloop.counter }}">{{ i }}</td>
    {% endfor %}
Sign up to request clarification or add additional context in comments.

2 Comments

There are 5 items in quantities, so I want to assign q1 to the first, q2 for the second and so on
@YantraLogistics updated answer according to new details

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.