0

I have a JSON object that I am looping through to dynamically create x amount of ULs then LIs. I need to create two {{#each}} to create the content. However when I add a CSS class to my handlebars template it does not come through onto the UL as it does in the second {{#each}} - how do I stop this? Here is the template:

<div class="{{panel-container__Css-class}} {{panel-menu__Css-class}}" data-component="panel">
  {{#each sections}}
  <ul id="{{id}}" class="{{panel-menu__Css-class}}">
    {{#each list}}
    <li><a href="{{url}}">{{title}}</a></li>
    {{/each}}
  </ul>
  {{/each}}
</div>

Here is what i am passing in:

    <nav data-component="navigation">
        {{> nav-dropdown menu-button__Css-class="menu-button" menu-button__Css-class-nav="panel"  target-id="panel-nav"  }}
        {{> nav-dropdown menu-button__Css-class="region-button" menu-button__Css-class-nav="region" target-id="panel-region" menu-button__copy=panel.copy}}
        {{!--var links = [{"title": "Test","url": "/"}];--}}
        {{> panel panel-menu__Css-class="navigation__menu-styles" panel-container__Css-class="navigation__menu-container" sections=navigation.sections links=navigation.sections.list  }}
    </nav>
2
  • An ID must be unique. Use a class when you have multiple ul elements. Commented Jun 1, 2017 at 9:57
  • The id is unique because there may be multiple UL's within the nav - which hide and show content depending on what button was pressed @Gerard Commented Jun 1, 2017 at 9:58

1 Answer 1

1

I think what you are looking for is the Handlebars path that will allow you to obtain the value of panel-menu__Css-class from within {{#each sections}}. You need to understand that when you are within {{#each sections}}, your this context is the currently iterated element of the sections array. You must step up a level to the parent context which has the panel-menu__Css-class property you are trying to access:

<ul id="{{id}}" class="{{../panel-menu__Css-class}}">
Sign up to request clarification or add additional context in comments.

Comments

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.