Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 426
Yevhenii Herasymchuk Avatar asked Nov 29 '25 07:11

Yevhenii Herasymchuk


1 Answers

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

like image 57
Yevhenii Herasymchuk Avatar answered Dec 01 '25 20:12

Yevhenii Herasymchuk