Get index value in Skuid merge syntax loop

  • 1
  • Question
  • Updated 10 months ago
  • Answered
Yo!

Sorry if this has been asked already. How do I get the index of a loop created via merge syntax (used in a template component). For example, something like this (which doesn't work):

{{#$Model.MyLovelySkuidModel.data}}
<li>{{index}} - {{{Name}}}</li>
{{/$Model.MyLovelySkuidModel.data}}

Cheers!

Louis
Photo of Louis Skelton

Louis Skelton

  • 4,970 Points 4k badge 2x thumb

Posted 10 months ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,026 Points 20k badge 2x thumb
If your template is bound to a model it will loop over all the rows in that model.  You don't need the first or last line.  {{index}} -{{Name}} will work fine. 

I think I am misunderstanding something here.....
Photo of Louis Skelton

Louis Skelton

  • 4,970 Points 4k badge 2x thumb
H Rob,

So this is where a template isn't bound to a model. Instead, I'm just using merge syntax to loop through the rows of a model. I need to include HTML both above and below the looped area - which is why I can't just bind the template to a model and have it loop automatically.

e.g:

SOME HTML
{{#$Model.MyLovelySkuidModel.data}}
    <li>{{index}} - {{{Name}}}</li>
{{/$Model.MyLovelySkuidModel.data}} SOME MORE HTML
If I were instead to use three templates (e.g.)

Template 1: Some HTML
Template 2: Repeating list bound to a model
Template 3: Some more HTML

The template syntax interferes with my HTML - hence why I just want to do it all in one template using the merge syntax.
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,758 Points 10k badge 2x thumb
Louis,

Try adding a UI Only formula field to your model and make the formula {{index}}.  Then add the formula field to your template.

Thanks,

Bill
Photo of Louis Skelton

Louis Skelton

  • 4,970 Points 4k badge 2x thumb
Golly - that's done it! Amazing. Cheers Bill!