Skip to content

Commit 715e950

Browse files
authored
Merge pull request #756 from Jeffrey-mu/main
Include advanced usage examples
2 parents 29b076c + cabe314 commit 715e950

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

examples/slot/body.ejs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>body</div>

examples/slot/footer.ejs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>footer</div>

examples/slot/index.ejs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
<div>
3+
<%-include('./layout.ejs', {
4+
body: include('./body.ejs'),
5+
footer: include('./footer.ejs')
6+
})%>
7+
</div>
8+
9+
<hr>
10+
11+
<div>
12+
<%-include('./layout.ejs', {
13+
footer: include('./footer.ejs')
14+
})%>
15+
</div>

examples/slot/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Advanced use of "include", fast layout, and dynamic rendering components.
3+
*/
4+
5+
var ejs = require('../../lib/ejs');
6+
var read = require('fs').readFileSync;
7+
var join = require('path').join;
8+
var path = join(__dirname, '/index.ejs');
9+
10+
var ret = ejs.compile(read(path, 'utf8'), {filename: path})({title: 'use slot'});
11+
12+
console.log(ret);

examples/slot/layout.ejs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>layout</title>
8+
</head>
9+
10+
<body>
11+
<div>
12+
<h2><%=title%></h2>
13+
14+
<% if (typeof body !== 'undefined') { %>
15+
<%- body %>
16+
<% } else { %>
17+
<p>This is the default body content.</p>
18+
<% } %>
19+
20+
<div>description</div>
21+
22+
<%- footer %>
23+
</div>
24+
25+
</body>
26+
27+
</html>

0 commit comments

Comments
 (0)