Skip to content

Instantly share code, notes, and snippets.

Last active September 1, 2020 09:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bitsapien/e3130b01d04d57fa4cf5a9200dba50be to your computer and use it in GitHub Desktop.
Single line templating engine
* Problem: When you want to do very basic templating with very little to no logic, for example templating a mail or an HTML.
const render = (templateData, templateHTML) =>
(renderedContent, dataVar) =>
renderedContent.replace(new RegExp(`{{${dataVar[0]}}}`, 'g'), dataVar[1]),
/* Usage
* > render({"Name": "Yes"}, "Hello, {{Name}} {{Name}}")
* 'Hello, Yes Yes'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment