The easiest string templating
- Easy data replacement in the string
- No dependency
- Compatible with all browsers
- Nanoweight helper
Use keys in double brackets to replace your data
'These {{something}} are so {{adjective}}!'.tmpl({
something: 'diamonds',
adjective: 'shiny',
})
// These diamonds are so shiny!
// define a project template here
const projectTmpl = `
<h2>{{name}}</h2>
<p>{{description}}</p>
`
// fetch a project data
const data = await (await fetch('path/to/data.json')).json()
// apply a project data to the template
const project = projectTmpl.tmpl(data)
// and append it
const projects = document.getElementById('projects')
projects.append(project)
Released under the MIT license