Search code examples
node.jshandlebars.jsemail-templates

Is there an official list for Handlebars reserved words?


After struggling with a template var named {{engine.x.y}}, which was "silently" showing nothing until I changed it for something else such as {{_engine.x.y}}, I saw that other words such as {{action}} seemed to be "reserved", with no "escaping" possibility...

Is there any list of such "reserved words" in order to lessen the "surprise factor" ? I couldn't find any.

EDIT

  • even more strange, when I use {{engine}} directly (not engine.x.y) it always gets replaced by the string ".hbs"

  • however in my context (Node v4.6 + email-templates + handlebars) {{action}} works correctly (linked problem above looks specific to Ember.js)


Solution

  • Found it - the issue isn't with Handlebars (which Josh Crozier found to not reserve any names in the comments above), it's with the email-templates library that you're using. The render function it uses sets several properties on the object that gets passed as the template context, meaning that if your object contains properties with the same name, they get clobbered.

    The relevant line of code in the email-templates source can be found here, but for the sake of completeness, the properties which get overwritten are:

    • filename (set to your template's filename)
    • engine (set to the file extension of the templating engine that's being used)
    • templatePath (set to the directory that contains your template)

    The most obvious solution would be to just change the name, but if that's not an option you may need to file an issue on their repo.