akdubya / dustjs

Asynchronous templates for the browser and node.js
http://akdubya.github.com/dustjs/
MIT License
1.44k stars 124 forks source link

Global objects not path-able #54

Open soci-viii opened 12 years ago

soci-viii commented 12 years ago

Pathing only works for objects that are in a context, not the global space. I've been using this kludge-tastic helper as a workaround to resolve paths out of the global namespace. I'd like to not have to use it.

function _global(chunk,ctx,bodies,params){
    var cur= ctx.get(params.root),
      i= 0
    while(true){
        var param= params["p"+(i++)]
        if(param === undefined)
            break
        cur= cur[param]||cur.get&&cur.get(param)
    }
    chunk.write(cur)
}

It's used like this: {#global root="foo" p0="bar" p1="baz"/}

From: makeBase({foo:{bar:{baz:77}}})