Search code examples
javascriptnode.jsvalidationmustache

How to validate mustache template with mustache.js?


I'm using the module ejs for validating ejs template and variables that come from the admin dashboard:

try {
  resolve(ejs.render(template, variables))
} catch (error) {
  reject(error)
}

And if there are some issues with this template, it throws an error, and I can send it to the client.

Also, I have a mustache template to validate. I'm using the same approach:

try {
  resolve(mustache.render(template, variables))
} catch (error) {
  reject(error)
}

But mustache doesn't throw an error at all, and if there is no variable, it just replaces it with an empty string.

How can I solve this issue? Need to validate templates properly.


Solution

  • I have found a solution in this fork of the library. Thanks to Scott it works like should.