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

Raise an error when the context is missing a required key #586

Closed
redking opened this issue Jul 29, 2013 · 1 comment
Closed

Raise an error when the context is missing a required key #586

redking opened this issue Jul 29, 2013 · 1 comment

Comments

@redking
Copy link

redking commented Jul 29, 2013

Hey,

I have a query regarding template compilation and missing keys.

I'm currently building a prototype that uses Handlebars for both client- and server-side templating; one of the concerns I have is the issue of errors due to missing or mis-spelled keys in the context. With Handlebars, such errors are only encountered at runtime when the template is evaluated. A missing key is rendered as an empty string, meaning that such mistakes are often difficult to discern in a page constructed from a number of templates.

Is it possible to evaluate templates in some sort of "strict" mode, or to override the way that evaluation is performed, such that a missing key will cause an error to be thrown? This would make it much simpler to find such problems, especially when a template is being edited by multiple developers.

I found a similar issue, but the proposed solution does not appear to work any longer

#318

@kpdecker
Copy link
Collaborator

There is a fair amount of overhead to add this sort of checking but you can work around this case by overriding Handlebars.Utils.escapeExpression. If you see undefined there throw an error. This won't catch unescaped expressions but for those cases you will end up with the undefined literal in your code.

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