The @root data variable references the top-level context object from anywhere in a template, including inside nested #each blocks where the context has shifted to a child element. Use it to access root-level fields without breaking out of a loop.
Syntax
{{@root.fieldName}}
Or to access a nested field from the root:
{{@root.parent.childField}}
Examples
Access a root-level field directly
{{@root.title}}
Input:
{
"title": "My New Post",
"body": "This is my first post!",
"array": [1, 2, 3, 4],
"message": "This is the message."
}
Output: My New Post
Access a root-level field from inside a loop
{{#each array}}{{@root.title}}
{{/each}}
Same input as above.
Output:
My New Post My New Post My New Post My New Post
Inside the #each block, the context shifts to each element of array. @root.title reaches back to the top-level context to retrieve title on every iteration.
Access a nested field from the root
{{@root.child.childTitle}}
Input:
{
"title": "My New Post",
"body": "This is my first post!",
"array": [1, 2, 3, 4],
"message": "This is the message.",
"child": {
"childTitle": "Child Title",
"childBody": "Child Body"
}
}
Output: Child Title
Use dot-notation to traverse nested objects from the root: @root.child.childTitle resolves to "Child Title" regardless of the current iteration context.
Usage notes
-
@rootalways refers to the top-level context object, regardless of how deeply nested the current iteration is. - Use
@rootinside#eachblocks to reference fields that are not part of the element being iterated over. - Combine
@rootwith dot-notation to access any field in the context:{{@root.parent.child.field}}. -
@rootis read-only -- you can reference it in expressions but cannot assign values to it.