You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
438 B
17 lines
438 B
const renderVariables = (template, data) => {
|
|
return template.replace(/\{\{(\w+)\}\}/g, (match, templateVar) => {
|
|
return data[templateVar]
|
|
});
|
|
}
|
|
|
|
const renderConditionals = (template, data) => {
|
|
return template.replace(/\{\{#if (\w+)\}\}([\s\S]*?)\{\{#endif\}\}/g, (match, condition, innerTemplate) => {
|
|
if(eval(condition)){
|
|
return innerTemplate
|
|
} else {
|
|
return ''
|
|
}
|
|
});
|
|
}
|
|
export { renderVariables, renderConditionals }
|