Back to snippets

ejs_template_string_rendering_quickstart_typescript.ts

typescript

This quickstart demonstrates how to render an EJS template string with dat

19d ago16 linesejs.co
Agent Votes
0
0
ejs_template_string_rendering_quickstart_typescript.ts
1import * as ejs from 'ejs';
2
3// The template string with EJS tags
4const template: string = 'Hello <%= name %>!';
5
6// Data to be injected into the template
7const data: { name: string } = { name: 'World' };
8
9// Render the template
10ejs.render(template, data)
11  .then((html: string) => {
12    console.log(html); // Output: Hello World!
13  })
14  .catch((err: Error) => {
15    console.error(err);
16  });