0

I have two for loops, the second one is inside the first one, I'd like to get the #index of the first loop inside the second loop.

this is my code:

    {{for parentObject}}
      {{for childObject}}
           <input id="myId{{:#indexParent}}{{:#index}}"/>
      {{/for}}
    {{/for}}

I've tried this code:

    {{for parentObject ~parent=#index}}
      {{for childObject}}
           <input id="myId{{:~parent}}{{:#index}}"/>
      {{/for}}
    {{/for}}

but it doesn't work!

Cœur
  • 37,241
  • 25
  • 195
  • 267
user2982862
  • 1
  • 1
  • 1

2 Answers2

0

I assume your objects are arrays. The ~parent=#index needs to be on the "item" template block - (the contents of {{for outerArray}}).

{{for parentObject}}
  {{for childObject  ~parent=#index}}
       <input id="myId{{:~parent}}{{:#index}}"/>
  {{/for}}
{{/for}}

You were picking up the index in the context one level too high.

BorisMoore
  • 8,444
  • 1
  • 16
  • 27
  • Yes my objects are arrays. So I tried this solution but it doesnt work! it displays nothing. Thanks. – user2982862 Nov 13 '13 at 09:41
  • If it displays nothing, then your childObject or parentObject iteration is not working. You should just test using "aaa{{for parentObject}}xxx{{for childObject}}yyy{{/for}}{{/for}}bbb", first. Does that output "aaabbb" or "aaaxxxyyy...bbb" or what? Maybe your issue is 'higher up'. After that try something like: "aaa{{for parentObject}}{{:#index}}xxx{{for childObject}}{{:#index}}xxxyyy{{/for}}{{/for}}bbb" – BorisMoore Nov 13 '13 at 22:31
0

Try this,

{{for parentObject ~parent=#index}}
  {{for childObject}}
       <input id="myId{{:#parent.index}}"/>
  {{/for}}
{{/for}}