Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to retrieve template name when providing instance of Context to dust.render #696

Closed
davidgwking opened this issue Aug 20, 2015 · 3 comments

Comments

@davidgwking
Copy link

It seems that I am unable to retrieve my template's name when providing an instance of Context to dust.render.

Here is a quick reproduction of the issue:

var dust = require('dustjs-linkedin');

dust.helpers.templateName = function (chunk, context, bodies, params) {
  var templateName = context.getTemplateName();

  return chunk.write(templateName);
};

var compiled = dust.compile('{@templateName/}', 'tmpl');
dust.loadSource(compiled);

dust.render('tmpl', dust.makeBase({}).push({}), function(err, name) {
  if (err) return done(err);

  console.log('base: %s', name);
});

dust.render('tmpl', {}, function(err, name) {
  if (err) return done(err);

  console.log('data: %s', name);
});

It seems that if an instance of Context is created and passed to render, it is never provided a templateName property. I see that context.wrap immediately returns instances of Context. As it is, it seems that it is impossible to set a Context's templateName property via API.

I'm left wondering if I'm missing something obvious or whether this is a purposeful design decision that is intended to prevent something dangerous.

Is the expectation that we should monkey patch this property in user land?

@sethkinast
Copy link
Contributor

Thanks for the detailed repro, I will dive into this probably tomorrow.

@sethkinast
Copy link
Contributor

Just to update, I'm working on a small refactor that touches all the places that we set template names to make sure they're consistent.

@davidgwking
Copy link
Author

@sethkinast thanks for the update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants