I\'ve got a handlebar template that loads a partial for a sub-element.
I would need to access a variable from the parent context in the calling template, from within
The easiest way to pass the parent context to the partial is to do the loop inside the partial. This way the parent context is passed by default and when you do the loop inside the partial the {{../variable}}
convention can access the parent context.
example fiddle here.
The Data
{
color: "#000"
items: [
{ title: "title one" },
{ title: "title two" },
]
}
The Template
Parent Color: {{color}}
{{> partial}}
The Partial
{{#each items}}
{{title}}
{{/each}}