jQuery simple template engine with support for loops and conditional data
Import this JS in your HTML
<script src="https://cdn.jsdelivr.net/npm/jquery-template-engine@1.0.1"></script>
or install it via npm
npm i --save jquery-template-engine
In your HTML, use the data-te
attributes for preparing the templates:
<h1 data-te-v="selection.country"></h1>
<p data-te-v="selection.city"></p>
<p>Other cities...</p>
<ul data-te-for="city of cities">
<li data-te-v="city.name"></li>
</ul>
And then you can use:
$("body").templateEngine({
selection : {
country: 'Spain',
city: 'Valencia'
},
cities : [
{name : 'Barcelona'},
{name : 'Madrid'},
{name : 'Sevilla'},
{name : 'Valencia'}
]
})