You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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
The text was updated successfully, but these errors were encountered: