Question

From a dust helper, how can I get the template name from which I'm called, eg:

var compiled = dust.compile("hi, I'm the {@whoami/} template!", "hi.dust");
dust.loadSource(compiled);

// should assert true
dust.render("hi.dust", {}, function(er, out) {
  assert(out, "hi, I'm the hi.dust template!");
});

Help me with the {@whoami} helper so it asserts true:

dust.helpers.whoami = function (chunk, context, bodies, params) {
  var str = /* >>> HELP ME HERE <<< */;

  return chunk.write(str);
}

Thank you

Was it helpful?

Solution

templateName is put on the context, so you can just use context.templateName inside of your helper to access it. In a future version of dust, it is likely this will change to context.__templateName, because we realized you won't be able to put a variable named templateName in your context, but for now you're good to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top