Skip to content

Instantly share code, notes, and snippets.

@antonkalik
Created March 27, 2024 21:15
Show Gist options
  • Save antonkalik/92457b267d899322313e0724bb32994f to your computer and use it in GitHub Desktop.
Save antonkalik/92457b267d899322313e0724bb32994f to your computer and use it in GitHub Desktop.
Generate Template Helper
import path from 'path';
import fs from 'fs';
import handlebars from 'handlebars';
export const generateTemplate = <T>(name: string, props: T): string => {
const templatePath = path.join(__dirname, '..', 'src/templates', `${name}.hbs`);
const templateSource = fs.readFileSync(templatePath, 'utf8');
const template = handlebars.compile(templateSource);
return template(props);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment