Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export let handlebarsExample = (async () => {
const { default: Handlebars } = await import("npm:handlebars");
let source =
"<p>Hello, my name is {{name}}. I am from {{hometown}}. I have " +
"{{kids.length}} kids:</p>" +
"<ul>{{#kids}}<li>{{name}} is {{age}}</li>{{/kids}}</ul>";
let template = Handlebars.compile(source);
let data = {
"name": "Alan",
"hometown": "Somewhere, TX",
"kids": [{ "name": "Jimmy", "age": "12" }, { "name": "Sally", "age": "4" }],
};
return template(data);
})();
October 23, 2023