質問

ダストヘルパーから、私は私が呼ばれるテンプレート名をどうやって得ることができます、例えば:

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!");
});
.

{@whoami}ヘルパーを使ってtrueをアサートします。

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

  return chunk.write(str);
}
.

ありがとう

役に立ちましたか?

解決

templateNameはコンテキストに置かれているので、ヘルパーの内側にcontext.templateNameを使用してアクセスするだけです。将来のほこりのバージョンでは、これがcontext.__templateNameに変更される可能性があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top