-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.html
71 lines (65 loc) · 1.89 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tpl.js -- a js template Engine</title>
<style>
body {margin:0; padding:0;}
pre {
border-left: 10px solid #ccc;
background: #f9f9f9;
color: #777;
padding: .5em 10px;
}
</style>
</head>
<body>
<h3>HTML Template</h3>
<pre>
<div id="view"></div>
<script type="text/template" id="demo">
<p>Hi, I'm <#=author#><#=undefinedVariable#></p>
<#include('#tpl_job');#>
<p>I can write:
<#
for(var i=0; i<languages.length; i++) {
echo( (i===0?"":", ") + languages[i] );
}
#>
</p>
</script>
</pre>
<pre>
<script type="text/template" id="tpl_job">
<p>I am a <#=job#></p>
</script>
</pre>
<br><br>
<h3>Javascript</h3>
<pre>
document.getElementById('view').innerHTML = tpl('#demo', {author: "Jony", job: "Frontend Web Developer", languages: ["javascript", "php", "shell"]});
</pre>
<br><br>
<h3>Result as below</h3>
<div id="view"></div>
<script type="text/template" id="demo">
<p>Hi, I'm <#=author#><#=undefinedVariable#></p>
<#include('#tpl_job');#>
<p>I can write:
<#
for(var i=0; i<languages.length; i++) {
echo( (i===0?"":", ") + languages[i] );
}
#>
</p>
</script>
<script type="text/template" id="tpl_job">
<p>I am a <#=job#></p>
</script>
<a href="https://github.com/niceue/tpl.js" style="position:absolute;top:0;right:0;"><img src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<script type="text/javascript" src="tpl.js"></script>
<script>
document.getElementById('view').innerHTML = tpl('#demo', {author: "Jony", job: "Frontend Web Developer", languages: ["javascript", "php", "shell"]});
</script>
</body>
</html>