0
votes

I have a data structure like this.

var myModel {
    _id: 798698,
    username: "John",
    message: {
        message1: "Some cool messsage",
        message2: "I'm mad Ohio State lost"
    }
}

Then in my handlebars template I do something like this.

<div class="message">
<b>{{username}}:</b>
    {{#each message}}
        <div>{{this}}</div>
    {{/each}}
</div>

But that results in

Kevin: 
message1
message2
Tony:
message1 from tony
message 2 from tony

When I'm trying to figure out how to

Kevin: message1
Kevin: message2
Tony:  message1 from tony
Tony:  message 2 from tony

New to handlebars, trying to search the docs, and use common sense but I am not sure how to loop each message and place the username inside that loop?

1

1 Answers

1
votes
<div class="message"><b>{{username}}:</b>
    {{#each message}}
        <div>{{../username}}: {{this}}</div>
    {{/each}}
</div>