0
votes

I have the following:

 {{for Basket.Items itemVar="~product"}}
    {{for ~product.Qty}}
       ......
    {{/for}}
  {{/for}}

where ~product.Qty = 2. it only goes through the loop once. how do I make the inner for loop for the amount of times that Qty equals?

So I might have 3 basket items and 1 of those items I might have a qty of 2, so I want my template to display the item with qty of 2 twice

1

1 Answers

0
votes

To interate over a range of numbers, you need to put ~product.Qty not as an argument to {{for}} as in {{for ~product.Qty}}, but as named end property: {{for end=~product.Qty}}.

For example:

{{for Basket.Items itemVar="~product"}}
  {{for end=Qty||1}}
     <div>{{:#index}} {{:~product.Name}}</div>
  {{/for}}
{{/for}}

or

{{for Basket.Items itemVar="~product"}}
  {{for end=~product.Qty||1 itemVar="~item"}}
     <div>{{: ~item}} {{: ~product.Name}}</div>
  {{/for}}
{{/for}}

with:

data = {Basket: { 
    Items: [
        {Name: "A", Qty: 2},
        {Name: "B", Qty: 3},
        {Name: "C"},
        {Name: "D", Qty: 1}
    ]
}};