Skip to content

Adding scope.root

Choose a tag to compare

@phillipskevin phillipskevin released this 30 Oct 22:00
· 682 commits to master since this release

This adds a {[scope.root}} that you can use to access the data passed to a stache renderer function. This allows you to avoid scope walking with recursive partials:

const data = new DefineMap({
    name: "Earthworm Jim",
    child: {
        name: "Grey Worm",
        child: {
            name: "MyDoom"
        }
    },
    exclaim: '!!!'
});

const view = stache("AppTemplate", `
    {{<personAndChildren}}
        <span>{{name}} {{scope.root.exclaim}}</span>
        {{#./child}}
            <div>
                {{>personAndChildren this}}
            </div>
        {{/./child}}
    {{/personAndChildren}}

    {{>personAndChildren this}}
`);

#353