0

How can I nest for loops in SCA (Handlebars) template language?

For example; I have an array of arrays and I want to loop over the inner array elements:

// Loop 1
{{#each footerNavigationLinks}}
<ul class="footer-content-nav-list">
    // Nested loop
    {{#each objectToAtrributes item}}
        <li>aa
        <a {{objectToAtrributes item}}>
                {{text}}
            </a>
        </li>
    {{/each}}
</ul>
{{/each}}

And footerNavigationLinks is an array of arrays:

footerNavigationLinks: [
    [
        {text: 'Link a', href:'#'}
    ,   {text: 'Link b', href:'#'}
    ,   {text: 'Link c', href:'#'}
    ],
    [
        {text: 'Link a', href:'#'}
    ,   {text: 'Link b', href:'#'}
    ,   {text: 'Link c', href:'#'}
    ]
]
sazr
  • 24,984
  • 66
  • 194
  • 362

1 Answers1

0

Not familiar with the helpers that SCA is providing (I presume that objectToAtrributes is one of those), but I would suggest that your nested #each should just be

{{#each this}}

since at that point all you have is an array. Within the nested #each, applying the 'objectToAttributes' helper may make sense since you are now working with each object with the array. However, if this doesn't work, I would try removing the helper since you should already have access to the 'text' property without it.

rasmeister
  • 1,986
  • 1
  • 13
  • 19