-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
39 lines (35 loc) · 1.17 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Data Template Example</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div id="user-template" data-template="user-card">
<div class="panel panel-default">
<div class="panel-heading">{{ name }}</div>
<div class="panel-body">
Email: {{ email }}
</div>
</div>
</div>
<script>
function renderTemplate(id, data) {
var template = document.getElementById(id);
var templateString = template.innerHTML;
Object.keys(data).forEach(function(key) {
templateString = templateString.replace(new RegExp('{{ ' + key + ' }}', 'g'), data[key]);
});
template.innerHTML = templateString;
}
// Example data
var userData = {
name: 'John Doe',
email: 'john.doe@example.com'
};
renderTemplate('user-template', userData);
</script>
</body>
</html>