Skip to content

Instantly share code, notes, and snippets.

@allouis
Created August 15, 2023 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allouis/8eba11f9778d93e0894ac2621621ab10 to your computer and use it in GitHub Desktop.
Save allouis/8eba11f9778d93e0894ac2621621ab10 to your computer and use it in GitHub Desktop.
Handlebars.js escaping example
var assert = require('assert');
var handlebars = require('handlebars');
handlebars.registerHelper('html_returning_helper', function () {
return '<p>This is HTML</p>';
});
var template = handlebars.compile(`
{{#html_returning_helper}} {{/html_returning_helper}}
{{html_returning_helper}}
`);
var result = template({});
assert(result === `
<p>This is HTML</p>
&lt;p&gt;This is HTML&lt;/p&gt;
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment